Tomcat logback console appender 仅遵循 ROOT 级别而不是命名的 appender

Tomcat logback console appender follows ROOT level only and not named appenders

我在 Eclipse 中使用 Tomcat。我最近升级到 Neon 并在那里重新创建了我的 Tomcat 服务器配置。从那时起,我就无法将我的 Web 应用程序正确地登录到 Eclipse 控制台。具体来说,如果我在我的 Web 应用程序附加程序中设置 INFO 级别,它们将成功转到日志文件,而不是控制台。

奇怪的是,只有当我将 ROOT 级别从 WARN 更改为 INFO 时,控制台才会显示我的应用程序的 INFO 级别。但是当然,这也会将其他所有内容都放在 INFO 中,这使得它不是很有用。

我也通过 logback 发送所有 Tomcat 日志记录。对于我的启动配置,我在参数中使用:

-Dcatalina.base="C:\dev\eclipse\workspace\.metadata\.plugins\org.eclipse.wst.server.core\tmp0" -Dcatalina.home="C:\dev\apache-tomcat-7.0.52" -Dwtp.deploy="C:\dev\eclipse\workspace\.metadata\.plugins\org.eclipse.wst.server.core\tmp0\wtpwebapps" -Djava.endorsed.dirs="C:\dev\apache-tomcat-7.0.52\endorsed" -Djava.util.logging.manager="org.apache.juli.ClassLoaderLogManager" -Djava.util.logging.config.file="C:/dev/apache-tomcat-7.0.52/conf/logging.properties" -Ddeployment.security.SSLv2Hello=false -Ddeployment.security.SSLv3=false -Ddeployment.security.TLSv1=false -Ddeployment.security.TLSv1.1=true -Ddeployment.security.TLSv1.2=true -Dlogback.configurationFile="C:/dev/apache-tomcat-7.0.52/lib/logback.xml"

并在 class 路径中,我添加了 tomcat-juli.jarjul-to-slf4j-1.7.25.jar

这是我的 logback.xml:

<?xml version="1.0" encoding="UTF-8"?>
<configuration scan="true" scanPeriod="10 seconds">
 <!-- always a good idea to have an OnConsoleStatusListener    -->
 <statusListener class="ch.qos.logback.core.status.OnConsoleStatusListener" />  

    <appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender">
        <encoder>
            <pattern>%d{HH:mm:ss.SSS} [%thread] %-5level (%file:%line\) - %message%n</pattern>
        </encoder>
    </appender>

    <!-- Tomcat service output has been disabled so all stdout/stderr messages come here as well. -->
    <appender name="main" class="ch.qos.logback.core.rolling.RollingFileAppender">  -->
    <!--See also http://logback.qos.ch/manual/appenders.html#RollingFileAppender -->
        <File>C:/dev/apache-tomcat-7.0.52/logs/tomcat7.log</File>
        <Append>true</Append>
        <encoder>
            <Charset>UTF-8</Charset>
            <pattern>%5level [%thread] %date{ISO8601} %class{0}:%line %mdc{requestId} - %message %n%rootException</pattern>
        </encoder>
        <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
            <maxHistory>10</maxHistory>
            <FileNamePattern>C:/dev/apache-tomcat-7.0.52/logs/tomcat7.%d{yyyy-MM-dd}.log</FileNamePattern>
        </rollingPolicy>
    </appender>

  <!-- If desired, we can create a class logger with additivity false to put that in its own log file -->

  <!-- be quiet -->
  <logger name="org.apache.struts2.util.TokenHelper" level="ERROR" />
  <logger name="org.dbunit.dataset.AbstractTableMetaData" level="ERROR"/>
  <logger name="org.springframework.mock.web.MockServletContext" level="ERROR"/>
  <logger name="org.w3c.tidy" level="OFF"/>
  <logger name="com.opensymphony.xwork2.DefaultActionProxy" level="ERROR"/>

  <!-- having issues with logging -->
  <logger name="ch.qos" level="DEBUG" />

  <logger name="com.mycompany.web.product.Catalog" level="INFO" />

  <root level="WARN">
    <appender-ref ref="CONSOLE"/>
    <appender-ref ref="main"/>
   </root>

</configuration>

下面是我启动时在 Eclipse 控制台中得到的输出 Tomcat: 20:01:06,793 |-INFO in ch.qos.logback.classic.LoggerContext[default] - Found resource [C:/dev/apache-tomcat-7.0.52/lib/logback.xml] at [file:/C:/dev/apache-tomcat-7.0.52/lib/logback.xml] 20:01:06,938 |-INFO in ch.qos.logback.classic.joran.action.ConfigurationAction - debug attribute not set 20:01:06,974 |-INFO in ch.qos.logback.classic.joran.action.ConfigurationAction - Will scan for changes in [file:/C:/dev/apache-tomcat-7.0.52/lib/logback.xml] 20:01:06,975 |-INFO in ch.qos.logback.classic.joran.action.ConfigurationAction - Setting ReconfigureOnChangeTask scanning period to 10 seconds 20:01:06,980 |-INFO in ch.qos.logback.core.joran.action.StatusListenerAction - Added status listener of type [ch.qos.logback.core.status.OnConsoleStatusListener] 20:01:07,017 |-INFO in ch.qos.logback.core.joran.action.AppenderAction - About to instantiate appender of type [ch.qos.logback.core.ConsoleAppender] 20:01:07,023 |-INFO in ch.qos.logback.core.joran.action.AppenderAction - Naming appender as [CONSOLE] 20:01:07,032 |-INFO in ch.qos.logback.core.joran.action.NestedComplexPropertyIA - Assuming default type [ch.qos.logback.classic.encoder.PatternLayoutEncoder] for [encoder] property 20:01:07,079 |-INFO in ch.qos.logback.core.joran.action.AppenderAction - About to instantiate appender of type [ch.qos.logback.core.rolling.RollingFileAppender] 20:01:07,083 |-INFO in ch.qos.logback.core.joran.action.AppenderAction - Naming appender as [main] 20:01:07,086 |-INFO in ch.qos.logback.core.joran.action.NestedComplexPropertyIA - Assuming default type [ch.qos.logback.classic.encoder.PatternLayoutEncoder] for [encoder] property 20:01:07,100 |-INFO in c.q.l.core.rolling.TimeBasedRollingPolicy@391359742 - No compression will be used 20:01:07,103 |-INFO in c.q.l.core.rolling.TimeBasedRollingPolicy@391359742 - Will use the pattern C:/dev/apache-tomcat-7.0.52/logs/tomcat7.%d{yyyy-MM-dd}.log for the active file 20:01:07,111 |-INFO in c.q.l.core.rolling.DefaultTimeBasedFileNamingAndTriggeringPolicy - The date pattern is 'yyyy-MM-dd' from file name pattern 'C:/dev/apache-tomcat-7.0.52/logs/tomcat7.%d{yyyy-MM-dd}.log'. 20:01:07,111 |-INFO in c.q.l.core.rolling.DefaultTimeBasedFileNamingAndTriggeringPolicy - Roll-over at midnight. 20:01:07,119 |-INFO in c.q.l.core.rolling.DefaultTimeBasedFileNamingAndTriggeringPolicy - Setting initial period to Sun Jul 09 19:51:44 EDT 2017 20:01:07,124 |-INFO in ch.qos.logback.core.rolling.RollingFileAppender[main] - Active log file name: C:/dev/apache-tomcat-7.0.52/logs/tomcat7.log 20:01:07,124 |-INFO in ch.qos.logback.core.rolling.RollingFileAppender[main] - File property is set to [C:/dev/apache-tomcat-7.0.52/logs/tomcat7.log] 20:01:07,128 |-INFO in ch.qos.logback.classic.joran.action.LoggerAction - Setting level of logger [org.apache.struts2.util.TokenHelper] to ERROR 20:01:07,128 |-INFO in ch.qos.logback.classic.joran.action.LoggerAction - Setting level of logger [org.dbunit.dataset.AbstractTableMetaData] to ERROR 20:01:07,128 |-INFO in ch.qos.logback.classic.joran.action.LoggerAction - Setting level of logger [org.springframework.mock.web.MockServletContext] to ERROR 20:01:07,128 |-INFO in ch.qos.logback.classic.joran.action.LoggerAction - Setting level of logger [org.w3c.tidy] to OFF 20:01:07,128 |-INFO in ch.qos.logback.classic.joran.action.LoggerAction - Setting level of logger [com.opensymphony.xwork2.DefaultActionProxy] to ERROR 20:01:07,129 |-INFO in ch.qos.logback.classic.joran.action.LoggerAction - Setting level of logger [ch.qos] to DEBUG 20:01:07,129 |-INFO in ch.qos.logback.classic.joran.action.LoggerAction - Setting level of logger [com.sentrylink.web.product.Catalog] to INFO 20:01:07,129 |-INFO in ch.qos.logback.classic.joran.action.RootLoggerAction - Setting level of ROOT logger to WARN 20:01:07,130 |-INFO in ch.qos.logback.core.joran.action.AppenderRefAction - Attaching appender named [CONSOLE] to Logger[ROOT] 20:01:07,131 |-INFO in ch.qos.logback.core.joran.action.AppenderRefAction - Attaching appender named [main] to Logger[ROOT] 20:01:07,131 |-INFO in ch.qos.logback.classic.joran.action.ConfigurationAction - End of configuration. 20:01:07,132 |-INFO in ch.qos.logback.classic.joran.JoranConfigurator@14acaea5 - Registering current configuration as safe fallback point 20:01:07.606 [main] WARN (SetPropertiesRule.java:218) - [SetPropertiesRule]{Server/Service/Engine/Host/Context} Setting property 'source' to 'org.eclipse.jst.jee.server:web' did not find a matching property. 20:01:10,298 |-INFO in ch.qos.logback.classic.servlet.LogbackServletContainerInitializer@55d16720 - Adding an instance of class ch.qos.logback.classic.servlet.LogbackServletContextListener to the current web-app 20:01:17,590 |-INFO in ch.qos.logback.classic.servlet.LogbackServletContainerInitializer@75b3fa82 - Adding an instance of class ch.qos.logback.classic.servlet.LogbackServletContextListener to the current web-app 20:01:24,547 |-INFO in ch.qos.logback.access.tomcat.LogbackValve[null] - filename property not set. Assuming [conf\logback-access.xml] 20:01:24,547 |-INFO in ch.qos.logback.access.tomcat.LogbackValve[null] - Could NOT configuration file [C:\dev\eclipse\workspace\.metadata\.plugins\org.eclipse.wst.server.core\tmp0\conf\logback-access.xml] using property "catalina.base" 20:01:24,547 |-INFO in ch.qos.logback.access.tomcat.LogbackValve[null] - Found configuration file [C:\dev\apache-tomcat-7.0.52\conf\logback-access.xml] using property "catalina.home" 20:01:24,554 |-INFO in ch.qos.logback.access.joran.action.ConfigurationAction - debug attribute not set 20:01:24,554 |-INFO in ch.qos.logback.core.joran.action.StatusListenerAction - Added status listener of type [ch.qos.logback.core.status.OnConsoleStatusListener] 20:01:24,554 |-INFO in ch.qos.logback.core.joran.action.AppenderAction - About to instantiate appender of type [ch.qos.logback.core.rolling.RollingFileAppender] 20:01:24,554 |-INFO in ch.qos.logback.core.joran.action.AppenderAction - Naming appender as [FILE] 20:01:24,556 |-INFO in c.q.l.core.rolling.TimeBasedRollingPolicy@1990676241 - No compression will be used 20:01:24,556 |-INFO in c.q.l.core.rolling.TimeBasedRollingPolicy@1990676241 - Will use the pattern logs/data-access.%d{yyyy-MM-dd}.log for the active file 20:01:24,557 |-INFO in c.q.l.core.rolling.DefaultTimeBasedFileNamingAndTriggeringPolicy - The date pattern is 'yyyy-MM-dd' from file name pattern 'logs/data-access.%d{yyyy-MM-dd}.log'. 20:01:24,557 |-INFO in c.q.l.core.rolling.DefaultTimeBasedFileNamingAndTriggeringPolicy - Roll-over at midnight. 20:01:24,558 |-INFO in c.q.l.core.rolling.DefaultTimeBasedFileNamingAndTriggeringPolicy - Setting initial period to Sat Jul 08 22:21:36 EDT 2017 20:01:24,558 |-INFO in ch.qos.logback.core.joran.action.NestedComplexPropertyIA - Assuming default type [ch.qos.logback.access.PatternLayoutEncoder] for [encoder] property 20:01:24,572 |-INFO in ch.qos.logback.core.rolling.RollingFileAppender[FILE] - Active log file name: logs/data-access.log 20:01:24,572 |-INFO in ch.qos.logback.core.rolling.RollingFileAppender[FILE] - File property is set to [logs/data-access.log] 20:01:24,573 |-INFO in ch.qos.logback.access.joran.action.ConfigurationAction - End of configuration. 20:01:24,573 |-INFO in ch.qos.logback.access.joran.JoranConfigurator@783a197d - Registering current configuration as safe fallback point 20:01:24,573 |-INFO in ch.qos.logback.access.tomcat.LogbackValve[null] - Done configuring

此时我加载了一个网页,该网页触发了带有信息日志记录的目录 class。它成功登录了上面列出的 tomcat7.log 文件。但它没有出现在控制台中。

如果我将 Catalog appender 更改为 WARN 级别,日志文件会正确地删除 INFO 消息。如前所述,如果我将 Catalog appender 保留在 INFO 并且 将 ROOT appender 更改为 INFO,它将与其他所有内容一起显示在控制台中。

我已经升级到最新版本的 logback 和 slf4j,但没有帮助。任何帮助表示赞赏。

我能够解决这个问题。

我有一个自定义 context.xml 作为我的 Eclipse Tomcat 服务器配置的一部分。它具有属性 swallowOutput="true"。这对生产机器很有用(它会抑制标准输出),但对我在这里尝试做的事情却不利。设置为 false 后,一切正常。

为什么它以前在 Luna 中有效,但在 Neon 中无效,谁知道呢。