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

Example: replacing NamedLoggerFactory #4045

Closed
wants to merge 2 commits into from

Conversation

stefanobaghino-da
Copy link
Contributor

@stefanobaghino-da stefanobaghino-da commented Jan 14, 2020

This pull request is meant mostly as an example of how the ContextualizedLogger/LoggingContext would be used to replace the NamedLoggerFactory.

ApiSubmissionService in particular shows a simple example of enriching the LoggingContext (in particular with the command identifier).

Note that all services that use the LoggingServiceMarker to automatically generating code that logs internal and unknown gRPC errors has not been ported yet, I'm currently working on it.

Pull Request Checklist

  • Read and understand the contribution guidelines
  • Include appropriate tests
  • Set a descriptive title and thorough description
  • Add a reference to the issue this PR will solve, if appropriate
  • Include changelog additions in one or more commit message bodies between the CHANGELOG_BEGIN and CHANGELOG_END tags
  • Normal production system change, include purpose of change in description

NOTE: CI is not automatically run on non-members pull-requests for security
reasons. The reviewer will have to comment with /AzurePipelines run to
trigger the build.

A ContextualizedLogger is a wrapper around an Slf4j logger. It uses
call-by-name parameters to only construct logging lines when necessary.
The underlying context can be used by invoking withoutContext.

More interestingly, every call to one of its logging methods requires
the presence of an implicit LoggingContext.

A LoggingContext is a way of definining a set of pairs that a
ContextualizedLogger can log without the need of it being specified for
every call.

A new context can be created with newLoggingContext and, given an
implicit LoggingContext, pairs can be added or overwritten using
withEnrichedLoggingContext.

Pairs in the context will be appended to each event logged by a
ContextualizedLogger in the following form:

some text logged explicitly (context: {key1=value1, key2=value2)

If the underlying Logger is configured to use the Logstash encoder the
keys and values in the LoggingContext will also be added to the logging
event encoded in JSON format.

CHANGELOG_BEGIN
CHANGELOG_END
@stefanobaghino-da stefanobaghino-da changed the base branch from structured-logging to master January 17, 2020 13:37
@stefanobaghino-da stefanobaghino-da changed the title Example: replacing NamedLoggerFactory Replace NamedLoggerFactory Jan 17, 2020
@stefanobaghino-da stefanobaghino-da mentioned this pull request Jan 17, 2020
11 tasks
@stefanobaghino-da
Copy link
Contributor Author

Superseded by #4097.

@stefanobaghino-da stefanobaghino-da changed the title Replace NamedLoggerFactory Example: replacing NamedLoggerFactory Jan 17, 2020
@stefanobaghino-da stefanobaghino-da deleted the replace-named-logger-factory branch January 17, 2020 14:12
stefanobaghino-da added a commit that referenced this pull request Jan 17, 2020
stefanobaghino-da added a commit that referenced this pull request Jan 17, 2020
stefanobaghino-da added a commit that referenced this pull request Jan 17, 2020
stefanobaghino-da added a commit that referenced this pull request Jan 17, 2020
stefanobaghino-da added a commit that referenced this pull request Jan 17, 2020
stefanobaghino-da added a commit that referenced this pull request Jan 17, 2020
stefanobaghino-da added a commit that referenced this pull request Jan 20, 2020
stefanobaghino-da added a commit that referenced this pull request Jan 20, 2020
stefanobaghino-da added a commit that referenced this pull request Jan 20, 2020
stefanobaghino-da added a commit that referenced this pull request Jan 20, 2020
The generation of code to have logging in the services has been replaced
by helpers classes. This will allow to enrich the context received at
construction by the service implementations.
stefanobaghino-da added a commit that referenced this pull request Jan 21, 2020
* Replace NamedLoggerFactory

CHANGELOG_BEGIN
CHANGELOG_END

* Recover change lost in rebase

* Address #4045 (comment)

* Address #4045 (comment)

* Address two open review comments

Address #4045 (comment)
Address #4045 (comment)

* Address outstanding compilation errors

* Replace mocking with in-memory log collector

* Address #4097 (review)

* Address #4045 (comment)

The generation of code to have logging in the services has been replaced
by helpers classes. This will allow to enrich the context received at
construction by the service implementations.

* Use ContextualizedLogger for TrackerMap

* Remove deleted logging packages from artifacts.yaml

* Remove remaining deleted artifact from artifacts.yaml

* Address #4097 (comment)

* Address #4097 (comment)

* Address #4097 (comment)

* Address #4097 (comment)

* Annotate type of references to logErrorOnCall

* Address #4097 (comment)
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