1

Is there a system property to make Slf4J and Logback tell which logback.xml and logback-test.xml files it found and which one it is using? I 'd expect to see that on in the log itself or in System.out.

For example, I 've got a Java project that clearly has no src/main/resources/logback.xml nor a src/test/resources/logback-test.xml file but Logback does seem to find one when I run my unit tests. I do have up to 100 dependencies (none which should include a logback.xml in theory) and checking them all one by one is impractical.

Note that I cannot use <configuration debug="true"> in my configuration file as I don't know where my configuration file is to begin with. I would like the same effect though.

Geoffrey De Smet
  • 26,223
  • 11
  • 73
  • 120
  • 2
    Try running your app with `-Dlogback.debug=true` http://stackoverflow.com/questions/3802054/run-logback-in-debug – tony19 Nov 25 '16 at 13:45

1 Answers1

1

Use -Dlogback.debug=true as stated by Tony in the comments. Then this shows up:

15:14:22,155 |-INFO in ch.qos.logback.classic.LoggerContext[default] - Could NOT find resource [logback.groovy]
15:14:22,156 |-INFO in ch.qos.logback.classic.LoggerContext[default] - Found resource [logback-test.xml] at [file:/.../target/test-classes/logback-test.xml]
15:14:22,333 |-INFO in ch.qos.logback.core.joran.action.AppenderAction - About to instantiate appender of type [ch.qos.logback.core.ConsoleAppender]
15:14:22,338 |-INFO in ch.qos.logback.core.joran.action.AppenderAction - Naming appender as [consoleAppender]
15:14:22,354 |-INFO in ch.qos.logback.core.joran.action.NestedComplexPropertyIA - Assuming default type [ch.qos.logback.classic.encoder.PatternLayoutEncoder] for [encoder] property
15:14:22,378 |-INFO in ch.qos.logback.classic.joran.action.LoggerAction - Setting level of logger [org.optaplanner] to INFO
15:14:22,379 |-INFO in ch.qos.logback.classic.joran.action.RootLoggerAction - Setting level of ROOT logger to WARN
15:14:22,379 |-INFO in ch.qos.logback.core.joran.action.AppenderRefAction - Attaching appender named [consoleAppender] to Logger[ROOT]
15:14:22,379 |-INFO in ch.qos.logback.classic.joran.action.ConfigurationAction - End of configuration.
15:14:22,380 |-INFO in ch.qos.logback.classic.joran.JoranConfigurator@1e965684 - Registering current configuration as safe fallback point

From which specifically this line matters:

... - Found resource [logback-test.xml] at [file:/.../target/test-classes/logback-test.xml]

If nothing shows up, it's either using the default logging configuration (everything DEBUG) or not recognizing the system property. Good luck figuring out which case it is (vote for this jira).

Geoffrey De Smet
  • 26,223
  • 11
  • 73
  • 120
  • Slf4j does not support -Dslf4j.debug yet to figure out which logging implementation is used. [Vote for this jira.](http://jira.qos.ch/browse/SLF4J-381) – Geoffrey De Smet Nov 25 '16 at 15:29