[
https://issues.apache.org/jira/browse/LOG4J2-2975?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17289969#comment-17289969
]
Volkan Yazici commented on LOG4J2-2975:
---------------------------------------
Log4j provides SLF4J bridges in two flavors:
# {{log4j-slf4j-impl}} for SLF4J 1.7.25 and(?) earlier
# {{log4j-slf4j18-impl}} for SLF4J 1.8.X
SLF4J fluent API has been introduced in 2.0.0. To put it more precisely, it is
still yet to be released, there are only alpha releases dating back from 2019.
In 2.0.0, SLF4J will introduce the {{LoggingEventAware}} interface, where story
develops as follows:
{code:java}
package org.slf4j.spi;
public class DefaultLoggingEventBuilder {
private void innerLog(LoggingEvent logggingEvent) {
if (logger instanceof LoggingEventAware) {
((LoggingEventAware) logger).log(logggingEvent);
} else {
logViaPublicLoggerAPI(logggingEvent);
}
}
private void logViaPublicLoggerAPI(LoggingEvent logggingEvent) {
// ...
switch (logggingEvent.getLevel()) {
// ...
case INFO:
logger.info(msg, combinedArguments);
break;
// ...
}
}
}
{code}
Make a guess on the line number of {{logger.info(msg, combinedArguments)}}
statement above. Yes, you have guessed it right, *120*! Just like in your demo
app. There goes your story.
I see two potential approaches we can take here:
# Log4j introduces a {{log4j-slf4j20-impl}} module implementing
{{LoggingEventAware}}
# You stop using an unmaintained API (i.e., {{slf4j-api}}) and switch to a
better alternative ({{log4j-api}}) with a comprehensive feature set, vibrant
community and support
> Lambda expression call with log4j slf4j bridge logs the wrong line number
> -------------------------------------------------------------------------
>
> Key: LOG4J2-2975
> URL: https://issues.apache.org/jira/browse/LOG4J2-2975
> Project: Log4j 2
> Issue Type: Bug
> Components: SLF4J Bridge
> Affects Versions: 2.13.3
> Reporter: Daniel Gray
> Priority: Major
>
> The logger outputs the wrong log line (120 for INFO, 117 for DEBUG, etc.)
> instead of the line in the program that generated the log, when running with
> the slf4j bridge. *This causes potential confusion when a person debugging
> something is reading the logs as the line numbers are wrong!*
> I have prepared 2 simple CLI apps to show the correct behavior (with only
> Log4J) and the incorrect behavior (with the SLF4J bridge). Both are using the
> exact same configuration (log4j2.properties). The repositories of these
> sample projects are:
> Good behavior with a pure log4j:
> [https://github.com/danielthegray/log4j-nobugsample]
> Wrong behavior with the slf4j bridge:
> [https://github.com/danielthegray/slf4j-bugsample]
--
This message was sent by Atlassian Jira
(v8.3.4#803005)