运行时,Logback停止记录

时间:2018-10-30 16:51:52

标签: java spring-boot logging logback

我们将Logback-1.2.3与SpringBoot 2.0.0.RELEASE一起使用,并将Web应用程序打包到可以在Tomcat中运行的war文件中(Tomcat运行约30个war文件)。 Tomcat中的每个应用程序都会生成一个单独的日志文件。在应用程序启动时,日志记录已正确运行,但在一段时间(随机时间段和随机日志文件)后,日志记录会随机停止。我们的登录配置如下所示。

<?xml version="1.0" encoding="UTF-8"?>
<configuration debug="false">
    <property name="LOG_HOME" value="/var/logs/services" />
    <springProperty scope="context" name="log.name" source="spring.application.name" defaultValue="localhost.log"/>
    <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
        <encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
            <pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{50} - %msg%n</pattern>
        </encoder>
    </appender>
    <appender name="FILE"  class="ch.qos.logback.core.rolling.RollingFileAppender">
        <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
            <FileNamePattern>${LOG_HOME}/${log.name}.log.%d{yyyy-MM-dd}.log</FileNamePattern>
            <MaxHistory>30</MaxHistory>
        </rollingPolicy>
        <encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
            <pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{50} - %msg%n</pattern>
        </encoder>
        <triggeringPolicy class="ch.qos.logback.core.rolling.SizeBasedTriggeringPolicy">
            <MaxFileSize>10MB</MaxFileSize>
        </triggeringPolicy>
    </appender>
    <logger name="org.hibernate.type.descriptor.sql.BasicBinder"  level="INFO" />
    <logger name="org.hibernate.type.descriptor.sql.BasicExtractor"  level="INFO" />
    <logger name="org.hibernate.SQL" level="INFO" />
    <logger name="org.hibernate.engine.QueryParameters" level="INFO" />
    <logger name="org.hibernate.engine.query.HQLQueryPlan" level="INFO" />
    <root level="INFO">
        <appender-ref ref="STDOUT" />
        <appender-ref ref="FILE" />
    </root>
</configuration>

我检查了以下内容:

1. lsof -p <tomcat pid>
    I can not find the file descriptor of the corresponding log filename, which means that logfile has already been closed by Tomcat(Why?);
2. check the Tomcat console logfile(catalina.out)
    I found the following Exception, but don't known whether it makes sense;

    java.lang.NoClassDefFoundError: ch/qos/logback/classic/spi/ThrowableProxy
            at ch.qos.logback.classic.spi.LoggingEvent.<init>(LoggingEvent.java:119)
            at ch.qos.logback.classic.Logger.buildLoggingEventAndAppend(Logger.java:419)
            at ch.qos.logback.classic.Logger.filterAndLog_0_Or3Plus(Logger.java:383)
            at ch.qos.logback.classic.Logger.warn(Logger.java:692)
            at com.mchange.v2.log.slf4j.Slf4jMLog$Slf4jMLogger$WarnLogger.log(Slf4jMLog.java:223)
            at com.mchange.v2.log.slf4j.Slf4jMLog$Slf4jMLogger.log(Slf4jMLog.java:256)
            at com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread.run(ThreadPoolAsynchronousRunner.java:749)

Tomcat版本是8.5.32。

有什么办法解决这个问题?还是我们配置了错误的登录?

0 个答案:

没有答案