首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >logback :水平设置在logback中不起作用

logback :水平设置在logback中不起作用
EN

Stack Overflow用户
提问于 2016-03-24 20:52:58
回答 1查看 9.9K关注 0票数 1

我正在进行一个项目,在这个项目中,我使用slf4j与logback一起进行日志记录。问题是日志的级别是动态的,是由用户选择的。因此,用户也可以停止日志记录,这样他就可以在空间上获得信息(我们记录了很多东西,如果流量很大的话,代价可能很快就会很高)。

为此,我将一些变量保存在属性文件中,并在每次更改时重新加载它。但是,我并没有像医生所说的那样成功地让它与水平(禁用日志)一起工作。

这是我的logback.xml:

代码语言:javascript
复制
<?xml version="1.0" encoding="UTF-8"?>

<configuration scan="false"> 
<!-- We don't need the logback.xml to be checked every time, we will trigger in java
the reload if we need it -->

    <property file="/opt/program/log.properties"/>

    <contextListener class="ch.qos.logback.classic.jul.LevelChangePropagator">
        <resetJUL>true</resetJUL>
    </contextListener>

    <!-- To enable JMX Management -->
    <jmxConfigurator/>

    <appender name="console" class="ch.qos.logback.core.ConsoleAppender">
        <encoder>
            <pattern>${PATTERN_LOGS}</pattern>
        </encoder>
    </appender>

     <appender name="generalFile" class="ch.qos.logback.core.rolling.RollingFileAppender">
         <file>${LOG_GENERAL_PATH}.log</file>
         <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy"> 
            <fileNamePattern>${LOG_GENERAL_FILENAME}.%d{yyyy-MM-dd}.log</fileNamePattern>
            <MaxHistory>30</MaxHistory>
          </rollingPolicy>
        <encoder>
            <pattern>${PATTERN_LOGS}</pattern>
        </encoder>
      </appender>

      <appender name="httpFile" class="ch.qos.logback.core.rolling.RollingFileAppender">
         <file>${LOG_HTTP_PATH}.log</file>
         <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy"> 
            <fileNamePattern>${LOG_HTTP_FILENAME}.%d{yyyy-MM-dd}.log</fileNamePattern>
            <MaxHistory>30</MaxHistory>
          </rollingPolicy>
        <encoder>
            <pattern>${PATTERN_LOGS}</pattern>
        </encoder>
      </appender>

       <appender name="errorFile" class="ch.qos.logback.core.rolling.RollingFileAppender">
         <file>${LOG_ERROR_PATH}.log</file>
         <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy"> 
            <fileNamePattern>${LOG_ERROR_FILENAME}.%d{yyyy-MM-dd}.log</fileNamePattern>
            <MaxHistory>30</MaxHistory>
          </rollingPolicy>
        <encoder>
            <pattern>${PATTERN_LOGS}</pattern>
        </encoder>
        <filter class="ch.qos.logback.classic.filter.ThresholdFilter">
            <level>ERROR</level>
        </filter>
      </appender>

     <logger name="http" level="DEBUG" additivity="false">
        <appender-ref ref="httpFile"/>
        <appender-ref ref="generalFile"/>
        <appender-ref ref="console"/>
    </logger>

    <root level="${LEVEL_ROOT}">
        <appender-ref ref="console"/>
        <appender-ref ref="generalFile"/>
        <appender-ref ref="errorFile"/>
    </root>
</configuration>

当我激活状态消息时,这就是我从控制台得到的:

代码语言:javascript
复制
00:06:45,861 |-INFO in ch.qos.logback.classic.LoggerContext[default] - Could NOT find resource [logback.groovy]
00:06:45,861 |-INFO in ch.qos.logback.classic.LoggerContext[default] - Could NOT find resource [logback-test.xml]
00:06:45,862 |-INFO in ch.qos.logback.classic.LoggerContext[default] - Found resource [logback.xml] at [file:/root/Documents/project/projet%20OSM/Tomcat%20Installation/wtpwebapps/SekaiServer/WEB-INF/classes/logback.xml]
00:06:45,944 |-INFO in ch.qos.logback.classic.joran.action.LoggerContextListenerAction - Adding LoggerContextListener of type [ch.qos.logback.classic.jul.LevelChangePropagator] to the object stack
00:06:45,961 |-INFO in ch.qos.logback.classic.jul.LevelChangePropagator@3b0933e7 - Propagating DEBUG level on Logger[ROOT] onto the JUL framework
00:06:45,962 |-INFO in ch.qos.logback.classic.joran.action.LoggerContextListenerAction - Starting LoggerContextListener
00:06:45,962 |-INFO in ch.qos.logback.classic.joran.action.JMXConfiguratorAction - begin
00:06:45,968 |-INFO in ch.qos.logback.core.joran.action.AppenderAction - About to instantiate appender of type [ch.qos.logback.core.ConsoleAppender]
00:06:45,975 |-INFO in ch.qos.logback.core.joran.action.AppenderAction - Naming appender as [console]
00:06:45,993 |-INFO in ch.qos.logback.core.joran.action.NestedComplexPropertyIA - Assuming default type [ch.qos.logback.classic.encoder.PatternLayoutEncoder] for [encoder] property
00:06:46,091 |-INFO in ch.qos.logback.core.joran.action.AppenderAction - About to instantiate appender of type [ch.qos.logback.core.rolling.RollingFileAppender]
00:06:46,100 |-INFO in ch.qos.logback.core.joran.action.AppenderAction - Naming appender as [generalFile]
00:06:46,143 |-INFO in c.q.l.core.rolling.TimeBasedRollingPolicy - No compression will be used
00:06:46,148 |-INFO in c.q.l.core.rolling.TimeBasedRollingPolicy - Will use the pattern /opt/program/log/general.%d{yyyy-MM-dd}.log for the active file
00:06:46,155 |-INFO in c.q.l.core.rolling.DefaultTimeBasedFileNamingAndTriggeringPolicy - The date pattern is 'yyyy-MM-dd' from file name pattern '/opt/program/log/general.%d{yyyy-MM-dd}.log'.
00:06:46,155 |-INFO in c.q.l.core.rolling.DefaultTimeBasedFileNamingAndTriggeringPolicy - Roll-over at midnight.
00:06:46,156 |-INFO in c.q.l.core.rolling.DefaultTimeBasedFileNamingAndTriggeringPolicy - Setting initial period to Sat Mar 26 00:03:15 CET 2016
00:06:46,159 |-INFO in ch.qos.logback.core.joran.action.NestedComplexPropertyIA - Assuming default type [ch.qos.logback.classic.encoder.PatternLayoutEncoder] for [encoder] property
00:06:46,165 |-INFO in ch.qos.logback.core.rolling.RollingFileAppender[generalFile] - Active log file name: /opt/program//log/general.log
00:06:46,165 |-INFO in ch.qos.logback.core.rolling.RollingFileAppender[generalFile] - File property is set to [/opt/program//log/general.log]
00:06:46,167 |-INFO in ch.qos.logback.core.joran.action.AppenderAction - About to instantiate appender of type [ch.qos.logback.core.rolling.RollingFileAppender]
00:06:46,168 |-INFO in ch.qos.logback.core.joran.action.AppenderAction - Naming appender as [httpFile]
00:06:46,170 |-INFO in c.q.l.core.rolling.TimeBasedRollingPolicy - No compression will be used
00:06:46,170 |-INFO in c.q.l.core.rolling.TimeBasedRollingPolicy - Will use the pattern /opt/program/log/http.%d{yyyy-MM-dd}.log for the active file
00:06:46,171 |-INFO in c.q.l.core.rolling.DefaultTimeBasedFileNamingAndTriggeringPolicy - The date pattern is 'yyyy-MM-dd' from file name pattern '/opt/program/log/http.%d{yyyy-MM-dd}.log'.
00:06:46,171 |-INFO in c.q.l.core.rolling.DefaultTimeBasedFileNamingAndTriggeringPolicy - Roll-over at midnight.
00:06:46,172 |-INFO in c.q.l.core.rolling.DefaultTimeBasedFileNamingAndTriggeringPolicy - Setting initial period to Sat Mar 26 00:03:15 CET 2016
00:06:46,172 |-INFO in ch.qos.logback.core.joran.action.NestedComplexPropertyIA - Assuming default type [ch.qos.logback.classic.encoder.PatternLayoutEncoder] for [encoder] property
00:06:46,174 |-INFO in ch.qos.logback.core.rolling.RollingFileAppender[httpFile] - Active log file name: /opt/program//log/http.log
00:06:46,174 |-INFO in ch.qos.logback.core.rolling.RollingFileAppender[httpFile] - File property is set to [/opt/program//log/http.log]
00:06:46,174 |-INFO in ch.qos.logback.core.joran.action.AppenderAction - About to instantiate appender of type [ch.qos.logback.core.rolling.RollingFileAppender]
00:06:46,175 |-INFO in ch.qos.logback.core.joran.action.AppenderAction - Naming appender as [errorFile]
00:06:46,177 |-INFO in c.q.l.core.rolling.TimeBasedRollingPolicy - No compression will be used
00:06:46,177 |-INFO in c.q.l.core.rolling.TimeBasedRollingPolicy - Will use the pattern /opt/program/log/error.%d{yyyy-MM-dd}.log for the active file
00:06:46,178 |-INFO in c.q.l.core.rolling.DefaultTimeBasedFileNamingAndTriggeringPolicy - The date pattern is 'yyyy-MM-dd' from file name pattern '/opt/program/log/error.%d{yyyy-MM-dd}.log'.
00:06:46,178 |-INFO in c.q.l.core.rolling.DefaultTimeBasedFileNamingAndTriggeringPolicy - Roll-over at midnight.
00:06:46,178 |-INFO in c.q.l.core.rolling.DefaultTimeBasedFileNamingAndTriggeringPolicy - Setting initial period to Thu Mar 24 19:50:38 CET 2016
00:06:46,179 |-INFO in ch.qos.logback.core.joran.action.NestedComplexPropertyIA - Assuming default type [ch.qos.logback.classic.encoder.PatternLayoutEncoder] for [encoder] property
00:06:46,190 |-INFO in ch.qos.logback.core.rolling.RollingFileAppender[errorFile] - Active log file name: /opt/program//log/error.log
00:06:46,190 |-INFO in ch.qos.logback.core.rolling.RollingFileAppender[errorFile] - File property is set to [/opt/program//log/error.log]
00:06:46,192 |-INFO in ch.qos.logback.classic.joran.action.LoggerAction - Setting level of logger [http] to DEBUG
00:06:46,192 |-INFO in ch.qos.logback.classic.jul.LevelChangePropagator@3b0933e7 - Propagating DEBUG level on Logger[http] onto the JUL framework
00:06:46,192 |-INFO in ch.qos.logback.classic.joran.action.LoggerAction - Setting additivity of logger [http] to false
00:06:46,192 |-INFO in ch.qos.logback.core.joran.action.AppenderRefAction - Attaching appender named [httpFile] to Logger[http]
00:06:46,194 |-INFO in ch.qos.logback.core.joran.action.AppenderRefAction - Attaching appender named [generalFile] to Logger[http]
00:06:46,194 |-INFO in ch.qos.logback.core.joran.action.AppenderRefAction - Attaching appender named [console] to Logger[http]
00:06:46,194 |-INFO in ch.qos.logback.classic.joran.action.RootLoggerAction - Setting level of ROOT logger to OFF
00:06:46,194 |-INFO in ch.qos.logback.classic.jul.LevelChangePropagator@3b0933e7 - Propagating OFF level on Logger[ROOT] onto the JUL framework
00:06:46,194 |-INFO in ch.qos.logback.core.joran.action.AppenderRefAction - Attaching appender named [console] to Logger[ROOT]
00:06:46,194 |-INFO in ch.qos.logback.core.joran.action.AppenderRefAction - Attaching appender named [generalFile] to Logger[ROOT]
00:06:46,194 |-INFO in ch.qos.logback.core.joran.action.AppenderRefAction - Attaching appender named [errorFile] to Logger[ROOT]
00:06:46,195 |-INFO in ch.qos.logback.classic.joran.action.ConfigurationAction - End of configuration.
00:06:46,195 |-INFO in ch.qos.logback.classic.joran.JoranConfigurator@78865c1d - Registering current configuration as safe fallback point
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2016-03-25 23:23:13

从您提供的logback状态消息中,根记录器按预期设置为平稳。但是,名为"http“的记录器被设置为调试,我怀疑这是问题的根源。

在任何情况下,从不同的记录器引用相同的附录都是个坏主意。此外,配置文件执行了两次,附加程序名为“generalFile”和“errorFile”。再次指出,从不同的记录器引用相同的附录是个坏主意,不支持.

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/36209809

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档