logback - remapping a log level for a specific logger

前端 未结 2 1581
渐次进展
渐次进展 2021-01-12 03:44

I have a logback configuration that has an appender with a threshold filter:



        
相关标签:
2条回答
  • 2021-01-12 04:43

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

    If others are searching for an example of how to remap you can take a look at the org.springframework.boot.logging.logback.LevelRemappingAppender class. With that appender it is possible to both remap what appender is finally used for the log event, and it is also possible to remap the level that is used for the final log event - e.g. by changing a DEBUG level into an INFO level.

    Usage example in logback config 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 remapping to a specific destination logger can make it harder to find the source code of the original log event - so use it with care.

    0 讨论(0)
  • 2021-01-12 04:44

    What you can do, is writing 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 output.

    0 讨论(0)
提交回复
热议问题