0

例如,我的日志文件中从 org.apache.axiom 和 org.apache.axis2 等包中收到了不需要的日志消息。我刚刚将我的网络应用程序从 log4j 切换到 logback。我的 tomcat 服务器仍然配置为使用 log4j。有人可以教育我为什么吗?这些消息是来自 Tomcat 吗?任何帮助,将不胜感激!

以下是相关代码:

web.xml

<web-app .....>
    <listener>
        <listener-class>ch.qos.logback.ext.spring.web.LogbackConfigListener</listener-class>
    <listener>
    <context-param>
        <param-name>logbackConfigLocation</param-name>
        <param-value>file:/opt/myapp/logback-server.xml</param-value>
    </context-param>

    <context-param>
       <param-name>logbackExposeWebAppRoot</param-name>
       <param-value>false</param-value>
    </context-param>

    <!-- Other Spring configuration -->
<web-app>

logback-server.xml

<configuration>
    <appender name="MAIN" class="ch.qos.logback.core.rolling.RollingFileAppender">
        <file>/usr/local/logs/server.log</file>
        <append>true</append>
        <filter class="ch.qos.logback.classic.filter.ThresholdFilter>
           <level>DEBUG</level>
        </filter>
        <encoder>
            <pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} | %p | %c %M | %m%n
        </encoder>
        <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
            <fileNamePattern>/usr/local/logs/server.log.%d</fileNamePattern>
    <appender>

    <appender name="TRACE" class="ch.qos.logback.core.rolling.RollingFileAppender">
        <file>/usr/local/logs/server-trace.log</file>
        <append>true</append>
        <filter class="ch.qos.logback.classic.filter.LevelFilter>
           <level>TRACE</level>
           <onMatch>ACCEPT</onMatch>
           <onMismatch>DENY</onMismatch>
        </filter>
        <encoder>
            <pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} | %p | %c %M | %m%n
        </encoder>
        <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
            <fileNamePattern>/usr/local/logs/server-trace.log.%d</fileNamePattern>
    <appender>

    <root level="DEBUG">
        <appender-ref ref="MAIN"/>
        <appender-ref ref="TRACE"/>
    </root>
</configuration>
4

1 回答 1

0

原来这是我的误解。

发生这种情况是因为我的根记录器的级别是 DEBUG,因此文件中未指定的所有其他包都记录在 DEBUG 级别或更高级别。将根级别定义更改为:

<root level="WARN">
  <appender-ref ref="MAIN"/>
  <appender-ref ref="TRACE"/>
</root>
于 2013-10-29T16:30:43.480 回答