Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Setting a log file name to include current date in Log4j

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.

like image 452
Tim Avatar asked Oct 10 '08 17:10

Tim


People also ask

What is the file name for log4j?

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.

What is logger name in log4j?

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.

Does log4j create log file?

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.


1 Answers

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> 
like image 89
gedevan Avatar answered Sep 23 '22 15:09

gedevan