Here's log4j properties using xml to output daily log messages to a file.
log4j.xml
<?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
<log4j:configuration debug="true" xmlns:log4j='http://jakarta.apache.org/log4j/'>
<appender name="file" class="org.apache.log4j.DailyRollingFileAppender"> <param name="File" value="C:/mylogs/myApp.log" /> <param name="DatePattern" value="'_'yyyy-MM-dd" /> <layout class="org.apache.log4j.PatternLayout"> <param name="ConversionPattern" value="[%p] %d %c %M - %m%n"/> </layout> </appender> <root> <level value="DEBUG" /> <appender-ref ref="file" /> </root> </log4j:configuration>From the above configuration the log messages will be written to a file daily inside 'C:/mylogs/' directory as shown below:
Daily Rolling Log Files |