编辑log4j后日志文件未翻转

时间:2019-07-15 09:59:25

标签: log4j

我最近更新了log4j配置,由于更改了它,因此它不再翻转。

在更新之前,为每个附加程序配置了以下内容:

<param name="MaxFileSize" value="20MB" />
<param name="MaxBackupIndex" value="10"/>

更新的配置:               

    <appender name="MainAppender" class="org.apache.log4j.RollingFileAppender">
            <param name="File" value="/var/log/info.log"/>
            <param name="Append" value="true"/>

            <param name="MaxFileSize" value="20MB" />
            <param name="MaxBackupIndex" value="1"/>

            <param name="Threshold" value="info"/>

            <layout class="org.apache.log4j.PatternLayout">
                    <param name="ConversionPattern" value="%d %-5p [%t] %c (%F:%L:%M()) - %m%n"/>
            </layout>
    </appender>

    <appender name="DebugAppender" class="org.apache.log4j.RollingFileAppender">
            <param name="File" value="/var/log/debug.log"/>
            <param name="Append" value="true"/>

            <param name="MaxFileSize" value="20MB" />
            <param name="MaxBackupIndex" value="4"/>

            <param name="Threshold" value="trace"/>

            <layout class="org.apache.log4j.PatternLayout">
                    <param name="ConversionPattern" value="%d %-5p [%t] %c (%F:%L:%M()) - %m%n"/>
            </layout>
    </appender>

    <appender name="ErrorAppender" class="org.apache.log4j.RollingFileAppender">
            <param name="File" value="/var/log/error.log"/>
            <param name="Append" value="true"/>

            <param name="MaxFileSize" value="10MB" />
            <param name="MaxBackupIndex" value="1"/>

            <param name="Threshold" value="error"/>

            <layout class="org.apache.log4j.PatternLayout">
                    <param name="ConversionPattern" value="%d %-5p [%t] %c (%F:%L:%M()) - %m%n"/>
            </layout>
    </appender>

    <appender name="stdout" class="org.apache.log4j.ConsoleAppender">
            <param name="Threshold" value="trace"/>

            <layout class="org.apache.log4j.PatternLayout"> 
                <param name="ConversionPattern" value="%d %-5p [%t] %c (%F:%L:%M()) - %m%n"/>
            </layout>
    </appender>

    <category name="com.group" additivity="false">
            <priority value="debug"/>
            <appender-ref ref="MainAppender"/>
            <appender-ref ref="DebugAppender"/>
            <appender-ref ref="ErrorAppender"/>
            <appender-ref ref="stdout"/>
    </category>

    <category name="org.hibernate" additivity="false">
            <priority value="info"/>
            <appender-ref ref="DebugAppender"/>
            <appender-ref ref="ErrorAppender"/>
    </category>

    <category name="org.springframework" additivity="false">
            <priority value="info"/>

            <appender-ref ref="DebugAppender"/>
            <appender-ref ref="ErrorAppender"/>
    </category>

    <root>
            <priority value="info"/>
            <appender-ref ref="DebugAppender"/>
            <appender-ref ref="ErrorAppender"/>
    </root>
</log4j:configuration>

我认为MaxBackupIndex的值不能为1,但是当我访问API文档时,我看到以下定义:

 protected  int     maxBackupIndex
          There is one backup file by default.

0 个答案:

没有答案