Can I disable an appender in logback on the xml config? I have my configuration and I want to put two appenders, one for database and other for text logs, but only one must
The easy way to choose a logging level for an appender is to use a ThresholdFilter
, e.g.:
${logging.appender.console.level:-OFF}
${pattern}
When you want to activate a particular appender you should run your jvm with an appropriate -D
option. For the appender defined above it would be:
java -Dlogging.appender.console.level=DEBUG
Of course if you activate automatic configuration reloading (http://logback.qos.ch/manual/configuration.html#autoScan) you can change filter level while the app is running.
The approach I've proposed is convenient when you don't want to change your logback config file every time you start the app (with different logging levels). You simply have to set properties used in logback config by running jvm with corresponfing -D
options.