Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add StdOutLogger and LoggingTrait #578

Draft
wants to merge 37 commits into
base: main
Choose a base branch
from
Draft

Conversation

Hectorhammett
Copy link
Contributor

@Hectorhammett Hectorhammett commented Sep 4, 2024

related: googleapis/gax-php#585

Add logging support to the HTTP calls for easy debugging.

@Hectorhammett Hectorhammett requested a review from a team as a code owner September 4, 2024 21:46
@bshaffer bshaffer changed the title Feat: Add the StdOutLogger and Logging Trait feat: add StdOutLogger and LoggingTrait Sep 5, 2024
src/ApplicationDefaultCredentials.php Outdated Show resolved Hide resolved
src/ApplicationDefaultCredentials.php Outdated Show resolved Hide resolved
src/HttpHandler/Guzzle6HttpHandler.php Outdated Show resolved Hide resolved
src/HttpHandler/Guzzle6HttpHandler.php Show resolved Hide resolved
$requestEvent->retryAttempt = $options['retryAttempt'] ?? null;
$requestEvent->serviceName = $options['serviceName'] ?? null;
$requestEvent->clientId = spl_object_id($this->client);
$requestEvent->requestId = spl_object_id($request);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

since this code is duplicated above, why not have private methods like logHttpRequest($request) and logHttpResponse($response, $requestEvent)?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In my mind, formatting the LogEvent and filling that data is not duty of the log function. The log function takes the generic log object and turns it into a json string to the docs specification, that's why I decided to have this code "duplicated", which in my mind is not really "duplicated" but is basically the same, mostly because one is for the response and one is for the request, and I did it this way in order to keep them separate from the logging logic.

I also thought perhaps a function to make a logEvent but voted against it as it would have to be flexible enough to acomodate the small differences between response and request but it can definitely be done.

src/Logging/LoggingTrait.php Outdated Show resolved Hide resolved
src/Logging/LoggingTrait.php Outdated Show resolved Hide resolved
src/Logging/StdOutLogger.php Outdated Show resolved Hide resolved
tests/Logging/StdOutLoggerTest.php Show resolved Hide resolved
src/ApplicationDefaultCredentials.php Outdated Show resolved Hide resolved
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants