-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Make location computation and message formatting more lazy #2329
Conversation
b531606
to
93bd5f9
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great simplification @ppkarwasz! 💯
- Since the
Message
is already populated with aloggerFqcn
and that is enough to resolve thelocation
in theLogEvent
, we don't need to resolve the location inAbstractLogger
, right? - Due to to
peekSource()
, when a message gets copied elsewhere,peekSource()
can be used to initialize thesource
, and reuse the already populated value, if present. Otherwise,getSource()
can calculate it, if requested. This is the crux of this locate-at-the-end implementation, right?
final LocationInfo info = event.getLocationInformation(); | ||
return new StackTraceElement( | ||
info.getClassName(), info.getMethodName(), info.getFileName(), Integer.parseInt(info.getLineNumber())); | ||
} | ||
|
||
@Override |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't this also be annotated with @Nullable
too? (Applies to other getSource()
changes delegating to peekSource()
.)
log4j-core/src/main/java/org/apache/logging/log4j/core/impl/MementoLogEvent.java
Show resolved
Hide resolved
log4j-core/src/main/java/org/apache/logging/log4j/core/impl/MementoLogEvent.java
Show resolved
Hide resolved
We move the computation of location and message formatting to the last method call executed before a message leaves the current thread.
41c42f1
to
79b6316
Compare
Right. Having the FQCN of the logger class allows us to retrieve the location at any time or never. Previously the location was computed eagerly based on the result of
Partially, the original If we just keep the boolean oldIncludeLocation = event.isIncludeLocation();
event.setIncludeLocation(false);
event.getSource();
event.setIncludeLocation(oldIncludeLocation); The |
We move the computation of location and message formatting to the last method call executed before a message leaves the current thread.
This has several consequences:
AbstractLogger
no longer needs to compute the location of the caller, many messages were refactored to fit in the 35 bytes of bytecode limit. OnlylogIfEnabled
methods with 4 or moreObject
parameters are over the limit andlogMessage
methods with 8 or moreObject
parameters,handleMessageException
and the constructors,AsyncAppender
do not include location information.Part of #2290.