Logback - reassigning the log level for a specific logger

I have a log configuration in which there is an application with a threshold filter:

<appender name="SYSLOG" class="ch.qos.logback.classic.net.SyslogAppender"> <filter class="ch.qos.logback.classic.filter.ThresholdFilter"> <level>INFO</level> </filter> ... </appender> 

This ensures that only information above is logged in syslog (warning, error). However, one of the third-party libraries that we use logs a specific event in DEBUG, and I would like to register this event in syslog. The first approach I had in mind was to try to reassign the log level in the logger, but not sure if this is possible? Sort of:

 <logger name="akka.some.Thing" level="DEBUG" logAs="INFO"> <appender-ref ref="SYSLOG" /> </logger> 

obviously, the "logAs" parameter does not exist, so I cannot do this. What would be the best approach to putting akka.some.Thing into the SYSLOG application, leaving the filter in place for other registrars?

Another approach would be to create a second append called SYSLOG2 that has no filter in place and set up a specific logger to use it, but wondered if there is a way to configure logback with just one SYSLOG added ...

Thanks,

+6
source share
2 answers

I know this is an old question, but it is actually possible to do what the OP wants to do with one SyslogAppender.

If others are looking for an example of how to reassign, you can take a look at the org.springframework.boot.logging.logback.LevelRemappingAppender class. With this application, you can either reassign that appender is finally used for the log event, or you can reassign the level that is used for the last log event - for example. by changing the DEBUG level to the INFO level.

Example usage in the log configuration file (taken from https://github.com/spring-projects/spring-boot/blob/master/spring-boot/src/main/resources/org/springframework/boot/logging/logback/defaults .xml ):

 <appender name="DEBUG_LEVEL_REMAPPER" class="org.springframework.boot.logging.logback.LevelRemappingAppender"> <!-- Optional: specify the destination logger the event ends up in --> <destinationLogger>org.springframework.boot</destinationLogger> <!-- Optional: specify log level remapping --> <remapLevels>INFO->DEBUG,ERROR->WARN</remapLevels> </appender> <logger name="org.thymeleaf" additivity="false"> <appender-ref ref="DEBUG_LEVEL_REMAPPER"/> </logger> 

Note that reassigning to a specific destination logger can make it difficult to find the original source log event, so use it with caution.

+6
source

What you can do is write a second logger + appender with the same output:

 <appender name="SYSLOG-2" class="ch.qos.logback.classic.net.SyslogAppender"> <filter class="ch.qos.logback.classic.filter.ThresholdFilter"> <level>DEBUG</level> </filter> ... </appender> <logger name="akka.some.Thing" level="DEBUG"> <appender-ref ref="SYSLOG-2" /> </logger> 

This will add your specific DEBUG tasks to the same conclusion.

+3
source

All Articles