问题描述
我正在使用log4j1.2.17和apache-extras-log4j--1.2.17.jar进行日志记录.
I am using log4j1.2.17 and apache-extras-log4j--1.2.17.jar for logging.
我的目的是根据大小滚动和归档文件.下面是log4j.xml
My purpose is to roll and archive the file based on size.Below is the log4j.xml
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/">
<appender name="R" class="org.apache.log4j.rolling.RollingFileAppender">
<param name="File" value="logger.log"/>
<param name="append" value="true"/>
<param name="encoding" value="UTF-8"/>
<rollingPolicy class="org.apache.log4j.rolling.FixedWindowRollingPolicy">
<param name="FileNamePattern" value="logger.log%i.gz" />
</rollingPolicy>
<triggeringPolicy class="org.apache.log4j.rolling.SizeBasedTriggeringPolicy">
<param name="MaxFileSize" value="${LOG_FILESIZE_LIMIT}"/>
</triggeringPolicy>
<layout class="org.apache.log4j.TTCCLayout">
<param name="ContextPrinting" value="true"/>
<param name="ThreadPrinting" value="true"/>
<param name="DateFormat" value="MM/dd/yyyy HH:mm:ss"/>
</layout>
</appender>
<root>
<priority value ="DEBUG"/>
<appender-ref ref="R"/>
</root>
</log4j:configuration>
$ {LOG_FILESIZE_LIMIT}是100MB.
${LOG_FILESIZE_LIMIT} is 100MB.
但未将MaxFileSize设置为100MB,并显示以下消息.
But its not setting the MaxFileSize to 100MB and gives below message.
log4j:WARN无法将属性[maxFileSize]设置为值"100MB"
log4j:WARN Failed to set property [maxFileSize] to value "100MB"
采用默认的maxfilesize(即10MB),并在文件达到10MB时对其进行归档.
Its taking default maxfilesize which is 10MB and archiving the file once it reaches to 10MB.
谢谢,安贾利
推荐答案
尝试将$ {LOG_FILESIZE_LIMIT}占位符设置为值 104857600 (相当于100MB字节),因为MaxFileSize参数可以接受长值.
Try setting the ${LOG_FILESIZE_LIMIT} placeholder to the value 104857600 (the equivalent of 100MB in bytes), as the MaxFileSize param accepts a long value.
这篇关于无法将MaxFileSize设置为值"100MB",在log4j中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!