首页 > 解决方案 > 如何使用 logback API 在 logback 配置中添加或删除记录器

问题描述

目的是启用配置的动态重新加载。我知道改变水平是可能的。

但是,我在这里找不到任何用于添加或删除记录器的方法LoggerContext 。

例如,在下面的 logback 配置文件中,如果我想使用 API 添加名为“chapters.configuration”的记录器,我该怎么做?

 <configuration>

  <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
    <!-- encoders are assigned the type
         ch.qos.logback.classic.encoder.PatternLayoutEncoder by default -->
    <encoder>
      <pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</pattern>
    </encoder>
  </appender>

  <logger name="chapters.configuration" level="INFO"/>

  <!-- Strictly speaking, the level attribute is not necessary since -->
  <!-- the level of the root level is set to DEBUG by default.       -->
  <root level="DEBUG">          
    <appender-ref ref="STDOUT" />
  </root>  
  
</configuration>

标签: logginglogbacklogback-classic

解决方案


推荐阅读