java - Configure log4j for maxsize and rotation -


i using log4j in java application. want config both of maxsize (max 1mb) , auto delete after 15 days.

# root logger option log4j.rootlogger=info, file  # direct log messages log file log4j.appender.file=org.apache.log4j.rollingfileappender log4j.appender.file.file=c:\\loging.log log4j.appender.file.maxfilesize=1mb log4j.appender.file.maxbackupindex=15 log4j.appender.file.layout=org.apache.log4j.patternlayout log4j.appender.file.layout.conversionpattern=%d{yyyy-mm-dd hh:mm:ss} %-5p %c{1}:%l - %m%n 

but seems in log4j can not config both of 2 requirements, right?

how can it? thank all.

your configuration fine, test change maxfilesize 1kb , run following code:

public class logtest {     static logger log = logger.getlogger("logtest");      public static void main(string[] args)     {         propertyconfigurator.configure("log4j.properties");//file should in classpath         (int = 0; < 20000; i++)             log.info("test");              system.out.println("done");      } } 

once completes, should having total 16 files loging.txt , loging.txt.1 loging.txt.15


Popular posts from this blog

How to calculate SNR of signals in MATLAB? -

c# - Attempting to upload to FTP: System.Net.WebException: System error -

ios - UISlider customization: how to properly add shadow to custom knob image -