unable to set MaxFileSize to value “100MB” in log4j

不羁的心 提交于 2019-12-11 04:05:51

问题


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

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} is 100MB.

But its not setting the MaxFileSize to 100MB and gives below message.

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

Its taking default maxfilesize which is 10MB and archiving the file once it reaches to 10MB.

Thanks, Anjali


回答1:


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.




回答2:


Check that there are no other versions of log4j on the classpath, I had this problem before where another third party set of jars also had an older version of log4j - removing it fixed the problem.



来源:https://stackoverflow.com/questions/24157371/unable-to-set-maxfilesize-to-value-100mb-in-log4j

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!