Can I disable an appender in logback?

前端 未结 2 1920
误落风尘
误落风尘 2020-12-09 10:47

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

2条回答
  •  粉色の甜心
    2020-12-09 11:14

    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.

提交回复
热议问题