According to the following post, you cannot do this with log4j : Use MaxBackupIndex in DailyRollingFileAppender -log4j
As far as I know, this functionality should have turned into log4j 2.0, but this effort has been lost. According to the logback site, logback is the intended successor to log4j, so you can use it.
There is an API called SLF4J that provides a generic logging API. It will load the actual logging implementation at runtime, so depending on the configuration you provided, it may use java.util.log or log4j or logback or any other library that can provide logging facilities. It will be a little forward to move from using log4j directly to using SLF4J, but they provide some tools to automate this process. After you convert your code to SLF4J, switching logs to the backend should just be a replacement for the configuration file.
PhilDin Sep 10 '10 at 9:53 2010-09-10 09:53
source share