Log file name to include current date in log4j

The question is a subset of this . I want to create a log file every day with the format of the log file name as follows: downloadmanageryyyy-MM-dd.log
Using DailyRollingAppender , but no log file is created at all.

My lo4j.xml looks like this:

  <?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE log4j:configuration SYSTEM "log4j.dtd"> <log4j:configuration xmlns:log4j='http://jakarta.apache.org/log4j/'> <appender name="InfoLogFile" class="org.apache.log4j.DailyRollingFileAppender"> <param name="File" value="downloadmanager.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> </log4j:configuration> 
+5
source share
1 answer

Sending the DailyRollingFileAppender with DailyRollingFileAppender will not rename the log file until the first message is logged some time after midnight.

You can try using the DatedFileAppender , which can be downloaded from here . Unlike the DailyRollingFileAppender , it will create a log file whose filename always contains today's date.

+6
source

Source: https://habr.com/ru/post/953565/


All Articles