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: ingest structured logs using stdout in LoggingHandler #812

Merged
merged 12 commits into from
Jan 1, 2022

Conversation

minherz
Copy link
Contributor

@minherz minherz commented Dec 30, 2021

Add configuration (edited:) redirectoToStdoutuseStructuredLogging to LoggingHandler class to support an option to print logs to STDOUT formatted as a one line Json and following the structured logging guidelines.
Implement Jsonification of the LogEntry object following the structured logging format.
Move metadata population to a standalone API to be used by LoggingHandler explicitly.

resolve warnings
change type for trace an spanId to be strings
create more realistic and visual test data:
- timestamp with more recent date
- json payload with various data types
refactor setAutoPopulateMetadata() to avoid setting flag to null
implement populateMetadata() API.
change write() to use the new API.
refactor SourceLocation.fromCurrentContext() to use a list of exclusion
prefixes instead of depth level as parameter.
change relevant unit tests to support the refactored changes.
modify publish() method to print structured logging if configured instead
of calling to Logging.write().
populate created LogEntry instance with metadata separately instead of
adding WriteOption.AUTO_POPULATE_METADATA.
refactor LoggingHandler to remove getLogging() method.
refactor unit tests to reflect the change in LoggingHandler.publish() implementation.
@minherz minherz self-assigned this Dec 30, 2021
@minherz minherz requested review from a team as code owners December 30, 2021 09:21
@product-auto-label product-auto-label bot added size: m Pull request size is medium. api: logging Issues related to the googleapis/java-logging API. labels Dec 30, 2021
@minherz minherz requested a review from losalex December 30, 2021 09:23
Copy link
Contributor

@losalex losalex left a comment

Choose a reason for hiding this comment

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

Thanks for your effort - good job! I left some comments, PTAL and let me know if those makes sense

Copy link
Contributor

@losalex losalex left a comment

Choose a reason for hiding this comment

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

Overall looks good - just fix whatever we agreed in comments. Also left some clarification regarding incomplete comment, hope it make sense

}

/**
* Adds a collection of Json fields that {@code value} parameter is serialized to to the current
Copy link
Contributor

Choose a reason for hiding this comment

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

Yes, I think name change like appendDictionary will be fine then

} else if (payload.getType() == Type.JSON) {
Payload.JsonPayload jsonPayload = (Payload.JsonPayload) payload;
formatter.appendJson(jsonPayload.getDataAsMap(), true);
} else if (payload.getType() == Type.PROTO) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Thank you!

@minherz minherz merged commit 749b9d2 into minherz/structured_logging Jan 1, 2022
@minherz minherz deleted the minherz/800 branch January 1, 2022 17:27
@minherz minherz changed the title feat: support structured logging in LoggingHandler using configuration feat: ingest structured logs using stdout in LoggingHandler Jan 2, 2022
minherz added a commit that referenced this pull request Jan 4, 2022
#812)

Implements populateMetadata() API.
Changes Logging.write() API to populate the provided list of log entries using the new API.
Refactors SourceLocation.fromCurrentContext() to use a list of exclusion instead of the call stack depth level as parameter.
Adds configuration `populateToStdout` to `LoggingConfig`.
Use the new configuration within `LoggingHandler` to print to STDOUT instead of ingesting the log by calling Logging.write().
Refactor LoggingImpl, LoggingHandler and unit tests.
minherz added a commit that referenced this pull request Jan 5, 2022
#812)

Implements populateMetadata() API.
Changes Logging.write() API to populate the provided list of log entries using the new API.
Refactors SourceLocation.fromCurrentContext() to use a list of exclusion instead of the call stack depth level as parameter.
Adds configuration `populateToStdout` to `LoggingConfig`.
Use the new configuration within `LoggingHandler` to print to STDOUT instead of ingesting the log by calling Logging.write().
Refactor LoggingImpl, LoggingHandler and unit tests.
minherz added a commit that referenced this pull request Jan 7, 2022
…ogs redirection to stdout in JUL handler (#808)

Aggregates the following work:
- #821
- #812
- #807
- #803
- #798

Fixes #689, #691, #799 and #800

* 🦉 Updates from OwlBot

See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md

Co-authored-by: Owl Bot <gcf-owl-bot[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api: logging Issues related to the googleapis/java-logging API. size: m Pull request size is medium.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants