How to create new log file each time application runs?
I would like to keep previous logs in any way. For example, I would prefer to name each new log file by time and date it was created. Otherwise, I agree to backup old log file into date and time filename.
Unfortunately, I can't see appropriate policies and/or triggers here: http://logback.qos.ch/manual/appenders.html
UPDATE
I made approximately as said in "duplicate"
<appender name="ROUTINEAPPENDER" class="ch.qos.logback.core.rolling.RollingFileAppender">
<file>logs/routine.log</file>
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<fileNamePattern>logs/routine%d{yyyyMMdd}%d{HHmmss,aux}.log</fileNamePattern>
<TimeBasedFileNamingAndTriggeringPolicy class="com.inthemoon.toolkit.StartupTimeBasedTriggeringPolicy" />
</rollingPolicy>
<encoder>
<pattern>%d{HH:mm:ss.SSS} - %C{0} - %msg%n</pattern>
</encoder>
</appender>
but my class com.inthemoon.toolkit.StartupTimeBasedTriggeringPolicy
is never called. I put breakpoint in start()
method but it never raised.
Also, no rolling occurs. Log file is created, but it always has the name routine.log
.
Also I don't understand, how parameters file
and filenamePattern
should coexist.
UPDATE 2
I have fixed UPDATE 1
class reference, but still don't have what I need. In given solution, the date time is inserted into OLD log filename. For example, if I ran program in 2013, it created routine.log
. Then I waited a year and run program in 2014. New log file will be created and have name routine.log
, while OLD 2013 log will be put into routine2014XXXXXXXXXX.log
, which is absolutely irrelevant.
I need create new file each time program starts and have this namely file marked with date-time stamp.