0
votes

How to configure the loggback in SL4J? My project has many classes: class1, class2, class3... I want to do this two things: Log all classes to a file appender named FILE1 with WARN level (class1, class2, class3...) Log one class named class1 to a file appender named FILE2 with DEBUG level.

The trouble is that when I configure the logger for class1 to FILE1 appender with WARN level I don't know how to configure the same logger (class1) to FILE2 appender with a different level (in this case DEBUG). I can configure both appenders to the same class but not with different levels.

1

1 Answers

1
votes

1/ Set log level to DEBUG for class1 logger

 <logger name="class1" level="DEBUG"/>

2/ For appender FILE1, use a ThresholdFilter to filter any logging events below log level WARN

<appender name="FILE1" class="ch.qos.logback.core.FileAppender"> 
<filter class="ch.qos.logback.classic.filter.ThresholdFilter"> 
  <level>WARN</level> 
</filter> 
 ...  
</appender> 

This will send all logging events above DEBUG to appender FILE2, but only events above WARN to appender FILE1.