SL4J设置与spring webapp使用tomcat不记录?

时间:2017-07-09 18:04:17

标签: java spring tomcat slf4j

我陷入了循环,无法弄清楚为什么当我的战争部署到tomcat时没有输出日志 - 但是如果我通过intellij在本地运行单元测试,则会按预期填充日志文件。

Web.xml包含:

<context-param>
    <param-name>logbackConfigLocation</param-name>
    <param-value>/WEB-INF/logback.xml</param-value>
</context-param>

src / main / java / resources / logback.xml(也在web-inf / logback.xml中有它)

<?xml version="1.0" encoding="UTF-8"?>

<appender name="FILE-AUDIT"
          class="ch.qos.logback.core.rolling.RollingFileAppender">
    <file>storagedebug.log</file>
    <encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
        <Pattern>
            %d{yyyy-MM-dd HH:mm:ss} %-5level %logger{36} - %msg%n
        </Pattern>
    </encoder>

    <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
        <!-- rollover daily -->
        <fileNamePattern>storagedebug.%d{yyyy-MM-dd}.%i.log
        </fileNamePattern>
        <timeBasedFileNamingAndTriggeringPolicy
                class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">
            <maxFileSize>10MB</maxFileSize>
        </timeBasedFileNamingAndTriggeringPolicy>
    </rollingPolicy>

</appender>

<logger name="com.app.storage" level="debug"
        additivity="false">
    <appender-ref ref="FILE-AUDIT" />
</logger>

<root level="error">
    <appender-ref ref="FILE-AUDIT" />
</root>

</configuration>

最后相关的依赖:

compile group: 'org.slf4j', name: 'slf4j-api', version: '1.7.7'
compile group: 'org.slf4j', name: 'jcl-over-slf4j', version: '1.7.25'
compile group: 'ch.qos.logback', name: 'logback-core', version:'1.1.2'
compile group: 'ch.qos.logback', name: 'logback-classic', 
version:'1.1.2'

我在Spring依赖项中加入了以下内容:

configurations.all {
    exclude group: "commons-logging", module: "commons-logging"
}

1 个答案:

答案 0 :(得分:0)

对于<file>storagedebug.log</file>,您可以尝试为日志文件设置绝对路径吗?由于目前,这是相对于tomcat bin目录。另外,请不要忘记更新<fileNamePattern>storagedebug.%d{yyyy-MM-dd}.%i.log的绝对路径