[ 
https://issues.apache.org/jira/browse/LOG4J2-2975?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17296801#comment-17296801
 ] 

Ralph Goers commented on LOG4J2-2975:
-------------------------------------

I started on this but then realized that the makeLoggingEventBuilder method 
returns a class only available in SLF4J-2.0.0 so if users are using the 1.8 api 
they will get a ClassNotFoundException when loading the SLF4J Logger adapter. 
That pretty much means this requires an slf4j-2.0.0 specific implementation. 

I should also note that the latest version of Logback,1.3.0-alpha5 from October 
2019, has a no-op implementation of the LoggingEventBuilder so the fluent API 
doesn't even work with Logback. This was reported in 
[https://jira.qos.ch/browse/LOGBACK-1530] and has had no activity since it was 
opened in October 2020. Prior to that it used DefaultLoggingEventBuilder and so 
would have had the exact same problem it does in Log4j - no FQCN is being 
passed into the log or info call so the Logger is going to default to thinking 
that DefaulLoggingEventBuilder is the caller. A bug really should be opened in 
SLF4J as this bug almost makes DefaultLoggingEventBuilder useless but I would 
guess it would meet the same fate as other SLF4J and Logback issues have for 
the last year.

[~daniel.gray] - I looked at your tests and noticed a couple of things.
 # You are using a pattern of (%c:%L). %c will use the logger name. If you had 
used %C I am quite sure you would see DefaultLoggingEventBuilder as the class 
name. 
 # The "success" version of your app doesn't use Log4j's fluent API. For a true 
apples to apples comparison it would be good to convert it to do that. It would 
also be nice to get feedback on whether it would make sense to add some of the 
methods the SLF4J api has. 

> SLF4J fluent API fails to capture call site location due to missing 
> LoggingEventAware implementation
> ----------------------------------------------------------------------------------------------------
>
>                 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
>            Assignee: Ralph Goers
>            Priority: Major
>             Fix For: 1.5
>
>
> 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)

Reply via email to