Skip to content
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

Incorrect line number when using Slf4jLoggerBackend #140

Open
MosheElisha opened this issue Mar 17, 2020 · 7 comments
Open

Incorrect line number when using Slf4jLoggerBackend #140

MosheElisha opened this issue Mar 17, 2020 · 7 comments
Labels
P3 type=defect Bug, not working as expected

Comments

@MosheElisha
Copy link

Hi,

I'm using Flogger with slf4j+log4j2 backend and a pattern that includes the line number (%line).
The line number in the log message does not match my code but instead matches the log statements inside Slf4jLoggerBackend

public void handleFormattedLogMessage(Level level, String message, Throwable thrown) {

Attaching a small project that reproduces the issue.

line-number-test.zip

Output:

2020-03-17T17:10:53,709 [main] INFO  example.LogTest:208 - Info
2020-03-17T17:10:53,712 [main] WARN  example.LogTest:211 - Warn
2020-03-17T17:10:53,712 [main] ERROR example.LogTest:214 - Severe

The expectation is that the line number will match the log statement in the LogTest. Accurate line number is very important in our log messages.

Thanks.

@cpovirk cpovirk added P3 type=defect Bug, not working as expected labels Mar 18, 2020
@hagbard
Copy link
Contributor

hagbard commented Mar 24, 2020

I'm afraid the SLF4J backend was a community contributed backend and isn't supported directly by Google. If you want to dig into the code and look for a solution I can probably answer some questions, or perhaps you can reach out to the original author ( https://github.com/cslee00 )

@cslee00
Copy link
Contributor

cslee00 commented Mar 24, 2020 via email

@MosheElisha
Copy link
Author

Hi,

Thanks for the replies. I'm using log4j2 - log4j-slf4j-impl version 2.13.1

@hagbard
Copy link
Contributor

hagbard commented Mar 24, 2020

""If the configured SLF4J back-end supports configuration of call-site
resolution it should be setup to grab callers
of com.google.common.flogger.FluentLogger#forEnclosingClass (or your custom
Flogger logger class, if any).""

That's probably not a great way to do this. You're better off (if the API allows) to use the LogSite that's available in the LogData. If the API doesn't allow it, then would you be better using the Flogger backend that talks directly to the backend you have (e.g. Log4J2).

The logger that logs things and the classes the log statements are in are not necessarily the same.

@MosheElisha
Copy link
Author

Hi,

If the API doesn't allow it, then would you be better using the Flogger backend that talks directly to the backend you have (e.g. Log4J2).

I see that log4j2 was added recently. I prefer to use log4j2 directly if possible but I noticed some issue with that as well (Opened issue #144).

Thanks!

@hagbard
Copy link
Contributor

hagbard commented Mar 25, 2020

I'll personally not work on this (no time) but I will see about looking into the Log4j2 issue and see if that's easy enough.

@MosheElisha
Copy link
Author

@hagbard Thank you. I appreciate that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
P3 type=defect Bug, not working as expected
Projects
None yet
Development

No branches or pull requests

4 participants