Peter Mularien Peter Mularien - 12 days ago 6
Java Question

How can I determine what log configuration source Logback actually used?

log4j has a property,

log4j.debug
, which will helpfully provide the user with an indication of which configuration file was actually used to configure the logging system.

I haven't been able to find anything equivalent with the (otherwise superior) Logback logging framework. Is there any way to print (for diagnostic purposes) at runtime, which configuration file Logback used to bootstrap itself?

[edit]
To clarify, I'd ideally like a solution that doesn't require me to modify the configuration file itself (since a badly assembled third-party JAR, for example, may be picked up incorrectly, and prior to my logback configuration XML).

Answer

You can set a Java system property to output Logback debugging info:

java -Dlogback.statusListenerClass=ch.qos.logback.core.status.OnConsoleStatusListener

This is further explained by the Logback documentation for automatic status printing (very bottom mentions forcing status output) and the logback.statusListenerClass property:

In the absence of status messages, tracking down a rogue logback.xml configuration file can be difficult, especially in production where the application source cannot be easily modified. To help identify the location of a rogue configuration file, you can set a StatusListener via the "logback.statusListenerClass" system property (defined below) to force output of status messages. The "logback.statusListenerClass" system property can also be used to silence output automatically generated in case of errors.

Comments