I've recently switched from log4j to logback and am wondering if there is an easy way to run logback in debug mode, similar to log4j's log4j.debug
property. I need to see where it is picking up my logback.xml
from.
The docs mention using a StatusPrinter
to print out logback's internal status, but that would require code changes.
I could not make it work using the chosen answer. However, the following worked:
Just add a file (
config-debug.xml
in this example) somewhere on your server and leave it there when you need to debug. Like the following.Run your application using the afore mentioned
-D
parameter.When things are back to normal, remove the
-D
parameter and restart your application.Source: Chapter 3: Logback configuration
You can set the status listener class via system property:
See: Logback manual
This is how I do it. I set a system property called 'log.level', then I reference it in logback.xml.
Edit:
The downside is that you MUST have 'log.level' always set. The way I deal with this is to check in my main method and set it to INFO if not already set, be sure to do this before you first logging calls. Then I can override on the command line, and have a sensible default.Here is how it looks in my logback.xml:
In eclipse you can have multiple run configurations. Open your main class. Go to Debug dropdown on eclipse toolbar and select Debug configurations. Click the New launch configuration icon at the top left. Give your launch configuration a better name. Click the Arguments tab under the name and enter -Dlog.level=debug or whatever you want. Click Close or Debug
You can do this again and specify -Dlog.level=warn for example.
[EDIT]
This has been fixed in Logback 1.0.4. You can now use
-Dlogback.debug=true
to enable debugging of the logback setup.-- Old Answer --
Unfortunately, there is no way to enable debugging via a System property. You have to use
<configuration debug="true">
in thelogback.xml
. Please submit a feature request.