You can use TimaAndSizeRollingAppender from http://www.simonsite.org.uk It works just like that.
On Fri, May 15, 2009 at 5:03 PM, <[email protected]> wrote: > > Curt Arnold writes: > > Actually surprised, I thought there was a upper limit on the > > maxBackupIndex. If you have a high maxBackupIndex and a file rolls, > > it will attempt to sequentially rename all the files. > > Ah ha. It's interesting that even the first roll, i.e. where no files > need to be renamed, seems to try to check all the possible files and > that it takes so long even when none of them exist. > > > Renaming is a risky and time-consuming operation, it would be much > > more reliable and faster if an appender just incremented the log file > > name and started a new log file. > > Is there an appender that works this way? That would for example save > off the existing log file with a suffix of the current date+time and > open up a new file when the log file gets bigger than some specified > size. > > thanks, > Paul > > > > > > > On May 14, 2009, at 4:48 PM, <[email protected]> <[email protected]> wrote: > > > > > > > > I have an application that uses the RollingFileAppender under log4j > > > 1.2.15 > > > on 64-bit linux on intel. > > > pru...@host /tmp/pr $ java -version > > > java version "1.6.0_07" > > > Java(TM) SE Runtime Environment (build 1.6.0_07-b06) > > > Java HotSpot(TM) 64-Bit Server VM (build 10.0-b23, mixed mode) > > > > > > I'd like to roll the logs, but effectively want to not have a limit on > > > how many can be generated. I tried setting the MaxBackupIndex to > > > something high, like 10 million. However, when the value gets to > > > 100,000 or higher my app pauses. This seems to happen about the time a > > > roll happens. The pauses seem to get longer the higher the value of > > > MaxBackupIndex and start at the first roll. If I lower the > > > MaxBackupIndex things speed up again. > > > > > > Two things. > > > > > > 1) Is there a better way to say, "just keep rolling"? > > > > > > 2) This seems like a bug. I'd expect the time to be just about the > > > same regardless of how many files already exist or the value of > > > MaxBackupIndex, at least up to the limit of an int. I've included two > > > files, a properties file and a java source. By increasing and > > > decreasing the value of maxBackupIndex I've been able to reproduce > > > this on the two systems I've tested on. > > > > > > Thanks for your help and your great software, I've been a happy log4j > > > user for quite a while. > > > > > > Paul > > > > > > log4j.appender.file=org.apache.log4j.RollingFileAppender > > > log4j.appender.file.maxFileSize=1KB > > > log4j.appender.file.maxBackupIndex=1000000 > > > log4j.appender.file.File=test.log > > > log4j.appender.file.threshold=info > > > log4j.appender.file.layout=org.apache.log4j.PatternLayout > > > log4j.appender.file.layout.ConversionPattern=%d{ABSOLUTE} %5p %c{1}: > > > %L - %m%n > > > log4j.rootLogger=TRACE, file > > > > > > > > > import org.apache.log4j.Logger; > > > import org.apache.log4j.PropertyConfigurator; > > > > > > public class MBI { > > > private static Logger logger = Logger.getLogger(MBI.class); > > > > > > public static void main(String args[]) { > > > PropertyConfigurator.configure("log4j.properties"); > > > int max = 1000; > > > for (int i = 0; i < max; i++) { > > > logger.info("TEST " + i); > > > } > > > } > > > } > > > > > > --------------------------------------------------------------------- > > > To unsubscribe, e-mail: [email protected] > > > For additional commands, e-mail: [email protected] > > > > > > > > > --------------------------------------------------------------------- > > To unsubscribe, e-mail: [email protected] > > For additional commands, e-mail: [email protected] > > --------------------------------------------------------------------- > To unsubscribe, e-mail: [email protected] > For additional commands, e-mail: [email protected] > >
