Log4j-根据时间和大小滚动

时间:2019-01-27 09:58:13

标签: log4j

我需要根据大小(每5 MB)和日期(每天)结合滚动日志文件,因此(使用附加功能)我创建了此log4j.xml

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE log4j:configuration>

<log4j:configuration debug="true">

    <appender name="ROLL" class="org.apache.log4j.rolling.RollingFileAppender">
        <rollingPolicy class="org.apache.log4j.rolling.TimeBasedRollingPolicy">
            <param name="ActiveFileName" value="${jboss.server.log.dir}/upload-doc-logs/fuse-log.log" />
            <param name="FileNamePattern"
                value="${jboss.server.log.dir}/upload-doc-logs/fuse-log.log.%d{yyyy-MM-dd}.%i" />
        </rollingPolicy>
        <triggeringPolicy class="org.apache.log4j.rolling.SizeBasedTriggeringPolicy">
            <param name="MaxFileSize" value="5242880" /> <!-- 5 MB -->
        </triggeringPolicy>

        <layout class="org.apache.log4j.PatternLayout">
            <param name="ConversionPattern"
                value="%d %-5p %c{1} %m %n" />
        </layout>
    </appender>

    <root>
        <appender-ref ref="ROLL" />
    </root>

</log4j:configuration>

日志文件仅每5 MB滚动一次,但不是每天滚动一次:问题出在什么地方?

0 个答案:

没有答案