Is it possible with any of the log4j appenders to write the logs with specific rotation time and retention limit.
The goal would be:
It seem that the rotation is possible but the limit of the retention time is not possible with log4j
The log4j version is 1.2.
The log4j. properties file is a log4j configuration file which stores properties in key-value pairs. The log4j properties file contains the entire runtime configuration used by log4j. This file will contain log4j appenders information, log level information and output file names for file appenders.
Log4j provides Appender objects which are primarily responsible for printing logging messages to different destinations such as console, files, NT event logs, Swing components, JMS, remote UNIX syslog daemons, sockets, etc.
Log4j allows logging requests to print to output destination, which is called an appender. JMS (Java Message Service) is one of Log4j appenders. JMSAppender publishes events to JMS and can perform JNDI requests that leading to possible vulnerability.
You can achieve it using custom log4j appender. MaxNumberOfDays - possibility to set amount of days of rotated log files.
Most of the answers are based on logback. But the question is about log4j 1.2 (old...)
the answer mentioning DailyRollingFileAppender will not work either.
org.apache.log4j.DailyRollingFileAppender
does not support the MaxBackupIndex
property see http://logging.apache.org/log4j/1.2/apidocs/org/apache/log4j/DailyRollingFileAppender.html (this is for RollingFileAppender
)
you may be interested in : Use MaxBackupIndex in DailyRollingFileAppender -log4j
and for a possible answer : Log4j Rollingpolicy and MaxbackupIndex
But you should probably use the slf4j log4j "emulation" (http://www.slf4j.org/legacy.html#log4j-over-slf4j) and route your log through logback (without any code change) where it's far easier to implements.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With