Failed to set MaxFileSize for value "100MB" in log4j

I am using log4j1.2.17 and apache-extras-log4j - 1.2.17.jar for logging.

My goal is to drill and archive a file based on size.Below is 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} - 100 MB.

But it does not set MaxFileSize to 100 MB and gives a message below.

log4j: WARN Failed to set property [maxFileSize] for value "100 MB"

The default is maxfilesize, which is 10 MB and archives the file when it reaches 10 MB.

Thanks Anjali

0
source share
2 answers

Try setting the placeholder $ {LOG_FILESIZE_LIMIT} to 104857600 (equivalent to 100 MB in bytes), because the MaxFileSize parameter takes a long value.

+3
source

Check if there are any other versions of log4j in the classpath, I had this problem before another third-party set of mailboxes had an older version of log4j - removing this problem fixed the problem.

0
source

All Articles