Spring LogBack配置未记录

时间:2018-04-11 20:29:43

标签: java spring-boot spring-logback

我正在开发Spring LogBack配置,因为我有2个日志文件( info.log error.log < / strong>分别只有INFO日志和ERROR日志。

实际上,当我运行应用程序时,会创建2个文件,但 error.log 为空,并且不会记录错误日志。

如果我的配置文件是以下内容有什么问题?

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<include resource="org/springframework/boot/logging/logback/base.xml" />
<include resource="org/springframework/boot/logging/logback/defaults.xml" />

<!-- APPENDERS DEFINITION -->
<appender name="LOG_INFO"
    class="ch.qos.logback.core.rolling.RollingFileAppender">
    <file>/myProject/info.log</file>
    <rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
        <!-- daily rollover -->
        <fileNamePattern>/myProject/info.%d{yyyy-MM-dd}.%i.log</fileNamePattern>
        <maxFileSize>50MB</maxFileSize>
        <maxHistory>30</maxHistory>
        <totalSizeCap>500MB</totalSizeCap>
    </rollingPolicy>
    <encoder>
        <pattern>
            %d{dd-MM-yyyy HH:mm:ss.SSS} %magenta([%thread]) %highlight(%-5level) %logger{36} - %msg%n
        </pattern>
    </encoder>
</appender>


<appender name="LOG_ERROR"
    class="ch.qos.logback.core.rolling.RollingFileAppender">
    <file>/myProject/error.log</file>
    <rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
        <!-- daily rollover -->
        <fileNamePattern>/myProject/error.%d{yyyy-MM-dd}.%i.log</fileNamePattern>
        <maxFileSize>50MB</maxFileSize>
        <maxHistory>30</maxHistory>
        <totalSizeCap>500MB</totalSizeCap>
    </rollingPolicy>
    <filter class="ch.qos.logback.classic.filter.LevelFilter">
        <level>ERROR</level>
        <onMatch>ACCEPT</onMatch>
        <onMismatch>DENY</onMismatch>
    </filter>
    <encoder>
        <pattern>
            %d{dd-MM-yyyy HH:mm:ss.SSS} %magenta([%thread]) %highlight(%-5level) %logger{36} - %msg%n
        </pattern>
    </encoder>
</appender>

<!--START ASYNC APPENDERS DEFINITION -->
    <appender name="ASYNC_LOG_INFO" class="ch.qos.logback.classic.AsyncAppender">
        <appender-ref ref="LOG_INFO" />
    </appender>
    <appender name="ASYNC_LOG_ERROR" class="ch.qos.logback.classic.AsyncAppender">
        <appender-ref ref="LOG_ERROR" />
    </appender>
<!--END ASYNC APPENDERS DEFINITION -->

<!--START LOCAL CONFIGURATION -->
<springProfile name="local">    
    <logger name="my.package" level="INFO"  additivity="false" >
        <appender-ref ref="ASYNC_LOG_INFO" />
        <appender-ref ref="ASYNC_LOG_ERROR" />
    </logger>
</springProfile>
<!-- END LOCAL CONFIGURATION -->

</configuration>

0 个答案:

没有答案