[
https://issues.apache.org/jira/browse/LOG4J2-555?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13944095#comment-13944095
]
Remko Popma commented on LOG4J2-555:
------------------------------------
Gary, looks like our messages crossed. :-) I agree with your solution to avoid
the potentially unnecessary call to {{messageFactory.newMessage}}.
Bruce, one more small thing I noticed: line 1160 of AbstractLogger in
log4j-555-bbrouwer-2.patch:
{code}
public void log(final Level level, final Marker marker, final Object message,
final Throwable t) {
if (isEnabled(level, marker, message, t)) {
logMessage(FQCN, level, marker, message, t);
}
}
{code}
Should this not be the below instead?
{code}
public void log(final Level level, final Marker marker, final Object message,
final Throwable t) {
log(FQCN, level, marker, message, t);
}
{code}
Finally, I strongly feel we should have a different name for the "internal API"
{{LoggerProvider.log}} methods (used by implementers/extenders) and the
"external API" {{Logger.log}} methods (used by users). I propose we rename the
LoggerProvider {{log}} methods to {{logIfEnabled}}. Other names would be fine
too, just not "log" :-)
If nobody objects I will rename the LoggerProvider {{log}} methods to
{{logIfEnabled}} and commit Bruce's "2" patch plus Gary's changes tomorrow (my
tomorrow, that is Saturday night US time).
> Location-based functionality broken in AbstractLoggerWrapper subclasses
> -----------------------------------------------------------------------
>
> Key: LOG4J2-555
> URL: https://issues.apache.org/jira/browse/LOG4J2-555
> Project: Log4j 2
> Issue Type: Bug
> Components: API, Core
> Affects Versions: 2.0-rc1
> Reporter: Remko Popma
> Assignee: Remko Popma
> Fix For: 2.0-rc2
>
> Attachments: LOG4J2-555-delegate.patch, log4j2-555-bbrouwer-2.patch,
> log4j2-555-bbrouwer.patch, log4j2-555-gg-v3.diff
>
>
> *How to reproduce*
> * Create a custom logger that extends {{AbstractLoggerWrapper}} (or generate
> one with the tool attached to LOG4J2-519)
> * In the custom logger provide a public method that invokes the {{log(Level,
> String)}} method
> * Configure a pattern layout that uses location, like %C for the logger FQCN
> * From a sample app, call the public method on your custom logger.
> * The output will show the class name of the custom logger instead of the
> class name of the calling class in the sample application.
> *Cause*
> {{AbstractLogger}}'s FQCN field is {{static final}} and initialized to
> {{AbstractLogger.class.getName()}}. Then, in
> {{Log4jLogEvent#calcLocation()}}, when walking over the stack trace elements,
> the element _following_ the FQCN is returned. So only loggers that directly
> subclass from {{AbstractLogger}} will work correctly. Loggers that inherit
> from {{AbstractLoggerWrapper}} are two levels removed from {{AbstractLogger}}
> and the {{calcLocation()}} method will not work correctly.
> *Solution*
> I think {{AbstractLogger}}'s FQCN field should be made non-static, and
> initialized to {{getClass().getName()}} in the constructor of
> {{AbstractLogger}}. {{Log4jLogEvent#calcLocation()}} can then be modified to
> return the {{StackElement}} whose class name matches the FQCN, instead of the
> next element. Location-based functionality should then work for arbitrarily
> deep subclass hierarchies of AbstractLogger.
--
This message was sent by Atlassian JIRA
(v6.2#6252)
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]