java - How can I set max total disk size for RollingFileAppender? -


i'm using log4j , log4j.extras create rollingfileappender rolls on 2 conditions:

  1. the working filesize exceeds maxfilesize threshold.
  2. the system's date changes.

following this guide, appender needs both timebasedrollingpolicy , sizebasedtriggeringpolicy, example:

<appender name="file_logger" class="org.apache.log4j.rolling.rollingfileappender">     <rollingpolicy class="org.apache.log4j.rolling.timebasedrollingpolicy">         <param name="activefilename" value="/fxh/logs/d3fixfeeds.log" />         <param name="filenamepattern" value="/fxh/logs/d3fixfeeds.%d{hh-mm}.%i.log" />             </rollingpolicy>     <triggeringpolicy         class="org.apache.log4j.rolling.sizebasedtriggeringpolicy">         <param name="maxfilesize" value="50000" /> <!--  in bytes -->     </triggeringpolicy>     <layout class="org.apache.log4j.patternlayout">         <param name="conversionpattern" value="%d{yyyy-mm-dd hh:mm:ss} %-5p - %m%n" />     </layout> </appender> 

how can set maximum limit on total disk space of log output? example, our server admin allots 40gb logs application, there anyway specify given dual rolling policies?

so far closest i've found maxbackupindex parameter. can't event work... example, neither of these truncates logs @ 5 files:

<appender name="file_logger" class="org.apache.log4j.rolling.rollingfileappender">     <param name="maxbackupindex" value="5"/>         <rollingpolicy class="org.apache.log4j.rolling.timebasedrollingpolicy">            <param name="activefilename" value="/fxh/logs/d3fixfeeds.log" />            <param name="filenamepattern" value="/fxh/logs/d3fixfeeds.%d{hh-mm}.%i.log" />                 ... 

nor

<appender name="file_logger" class="org.apache.log4j.rolling.rollingfileappender">     <rollingpolicy class="org.apache.log4j.rolling.timebasedrollingpolicy">            <param name="activefilename" value="/fxh/logs/d3fixfeeds.log" />            <param name="filenamepattern" value="/fxh/logs/d3fixfeeds.%d{hh-mm}.%i.log" />               <param name="maxbackupindex" value="5"/>                ... 

as @arigion says, doesn't log4j can you're asking, fortunately logback can. provides sizeandtimebasedrollingpolicy , totalsizecap allow create logs roll size , time and obey total storage limit, below:

<appender name="file_logger" class="ch.qos.logback.core.rolling.rollingfileappender"> <file>/fxh/logs/d3fixfeeds.log</file> <rollingpolicy class="ch.qos.logback.core.rolling.sizeandtimebasedrollingpolicy">   <!-- rollover daily -->   <filenamepattern>/fxh/logs/d3fixfeeds.%d{hh-mm}.%i.log</filenamepattern>    <maxfilesize>500kb</maxfilesize>        <maxhistory>60</maxhistory>    <totalsizecap>40gb</totalsizecap> </rollingpolicy> <encoder>   <pattern>%d{yyyy-mm-dd hh:mm:ss} %-5p - %m%n</pattern> </encoder> </appender> 

this not working example used best guess fields, let me know how goes.


Comments

Popular posts from this blog

php - Vagrant up error - Uncaught Reflection Exception: Class DOMDocument does not exist -

vue.js - Create hooks for automated testing -

Add new key value to json node in java -