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
Slf4j does not log correct class #190
Comments
The cause for this issue is that flyway's Slf4jLog class is a wrapper around SLF4J's real logger class. So, tinylog has no chance to detect the real caller class. Which caller method does Logback or Log4j output? |
Is there a workaround for this? Noticed quite a few "popular" third party libraries doing similar. Hazelcast is another example that has a "wrapper". Slf4j keeps a log name - is that usable for this? Flyway routes to slf4j as a priority. Will try to create an isolated test case and get back to you. |
SLF4J is just a logging API. For me, it is interesting what method other logging back-ends like Logback and Log4j output. Could you test it and paste the output here? |
After some research, I came to the conclusion that flyway has to use the LocationAwareLogger functionality for their custom Slf4jLog wrapper class. Otherwise no logging back-end would have any chance to detect the real caller method. |
Below is what I get from Logback: 14:09:33.329 [io-executor-thread-1] INFO io.micronaut.flyway.AbstractFlywayMigration - Running migrations for database with qualifier [default] |
Could you add also the caller method? I assume either me or you will be surprised ;-) |
Is this what you're looking for? This is with logback. Pattern is: %d{HH:mm:ss.SSS} [%thread] %-5level %class{36}.%M %L - %msg%n 03:30:28.377 [io-executor-thread-1] INFO i.m.flyway.AbstractFlywayMigration.runFlyway 88 - Running migrations for database with qualifier [default] |
So, Logback has the same issue. Flyway could fix the issue for all logging framework by using the LocationAwareLogger API for their Slf4jLog wrapper class. I found a good and working Slf4jLoggerwrapper class template here: |
It's able to log it correctly with default logback settings though (as per earlier comment). Is it a configuration issue. What pattern on tinylog would match the original logback output that shows the right classes? |
In your default Logback configuration, you use the logger category, neither the caller class name nor caller method. For such logger wrappers, SLF4J has introduced the LocationAwareLogger API. However, Flyway does not use the correct API for forwarding log entries. If they don't use the LocationAwareLogger API, there is no chance for any logging framework to output the correct caller class and method. The logger category would work nevertheless, but tinylog does not support logger categories by design. |
Sure, will contact Flyway and anyone else. Thanks |
Please let me know if I can support you for creating an issue or a pull request there. |
This closed issue has been locked automatically. However, please feel free to file a new issue. |
Describe the bug
When using slf4j-tinylog the correct class is not logged
To Reproduce
Steps to reproduce the behavior:
2021-01-01 15:33:23 [io-executor-thread-1] org.flywaydb.core.internal.logging.slf4j.Slf4jLog.info()
INFO: Flyway Community Edition 7.3.1 by Redgate
2021-01-01 15:33:23 [io-executor-thread-1] org.flywaydb.core.internal.logging.slf4j.Slf4jLog.info()
INFO: Database: jdbc:postgresql://127.0.0.1:6432/test (PostgreSQL 13.1)
2021-01-01 15:33:23 [io-executor-thread-1] org.flywaydb.core.internal.logging.slf4j.Slf4jLog.info()
INFO: Current version of schema "public": 1.1
Where these entries belong to different classes, e.g. the first is run from a class called VersionPrinter.
Environment
tinylog version: 2.2.1
Java version: 15
The text was updated successfully, but these errors were encountered: