Can I disable an appender in logback?

前端 未结 2 1919
误落风尘
误落风尘 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:03

    Not sure why you want to deactivate an appender, what are you trying to achieve by disabling.

    There are some ways to achieve it

    1. Add the appender in logback.xml and keep it commented. When you like to enable it then uncomment the appender and reload logback configuration (http://logback.qos.ch/manual/configuration.html#autoScan)
    2. Add a logger like the one given below and use appropriate logger for logging
        
          
          
          
            
          
    
          
            
          
           
    

    In this case also you have to reload the configuration when you modify logback configuration (logback.xml)

    1. If you know the conditions (to activate/deactivate) beforehand then use if else block to enable/disable

    On top of above 3 options you can create logback configurations progamatically

提交回复
热议问题