I would like to set the log file name for a log4j and log4net appender to have the current date. We are doing Daily rollovers but the current log file does not have a date. The log file name format would be
logname.2008-10-10.log
Anyone know the best way for me to do this?
edit: I forgot to mention that we would want to do this in log4net as well. Plus any solution would need to be usable in JBoss.
By default, Log4j looks for a configuration file named log4j2.xml (not log4j.xml) in the classpath. Web applications can specify the Log4j configuration file location with a servlet context parameter.
Log4j makes it easy to name loggers by software component. This can be accomplished by statically instantiating a logger in each class, with the logger name equal to the fully qualified name of the class. This is a useful and straightforward method of defining loggers.
Following is a sample configuration file log4j. properties to generate log files rolling over at midday and midnight of each day. If you wish to have an XML configuration file, you can generate the same as mentioned in the initial section and add only additional parameters related to DailyRollingFileAppender.
DailyRollingFileAppender is what you exactly searching for.
<appender name="roll" class="org.apache.log4j.DailyRollingFileAppender"> <param name="File" value="application.log" /> <param name="DatePattern" value=".yyyy-MM-dd" /> <layout class="org.apache.log4j.PatternLayout"> <param name="ConversionPattern" value="%d{yyyy-MMM-dd HH:mm:ss,SSS} [%t] %c %x%n %-5p %m%n"/> </layout> </appender>
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