fix: use logger name in default log configuration #21154
Draft
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
Using
%F
means "the class name of the class that called the logger method". I propose that the better and less confusing name to use is%c{1}
which means the name of the logger (%c
) as simple name ({1}
), meaning if there is a package name in the logger name cut it out.Confusion
This can be very confusing if meta-programming is used to resolve different loggers.
With
%F
the log line would state the name of the class containing the meta-logging code.If someone would want to configure the log level based they are likely to mistakenly assume that the class name in the logs would be the target of the level change. But that is not correct. The target still needs to be selected based on the logger name.
Also using
%F
defies the purpose or usefulness of resolving different loggers because it does no longer matter which logger a log is written to, the name in the log entry will always be the one containing the code that calls the "logger.log" method.That is why it is more useful and less confusing to use
%c
or%c{1}
.An example:
%F
gives a line withTimeExecutionInterceptor.java
But the logger used here was actually
MinMaxDataElementService
. Changing the log level ofTimeExecutionInterceptor
would not have any noticeable impact because that class is not the logger class.With
%c{1}
the same log line would bePerformance
Using
%F
is also discouraged since it has a larger performance overhead. This is because in order to find which class called the logger method the framework needs to throw a fake exception, catch it and look at the stack trace to find this out. This overhead does not exist with%c
.Documentation
The
%F
line is also given as an example in our documentation, we might want to change that as well?https://docs.dhis2.org/en/manage/reference/logging.html?h=#log-configuration