1

Can one configure log4j RollingFileAdapter not to change logfile name after midnight? With the configuration (see below) I'm using, if the logging starts on 2017-09-15 and continues overnight everything after 00:00 will be logged to another logfile 2017-09-16. I'd like to get full log in to the same file. Only if another run starts on 2017-09-16 then a new log would be created.

<appender name="file-output" class="org.apache.log4j.rolling.RollingFileAppender">
    <param name="ImmediateFlush" value="false"/>
    <param name="Threshold" value="INFO"/>
    <rollingPolicy name="file" class="org.apache.log4j.rolling.TimeBasedRollingPolicy">
        <param name="FileNamePattern" value="log/${logfilename}_%d{yyyy-MM-dd}.log"/>
    </rollingPolicy>
    <layout class="org.apache.log4j.PatternLayout">
        <param name="ConversionPattern" value="%d{yyyy-MM-dd HH:mm:ss} %-5p %m%n"/>
    </layout>
</appender>
tok
  • 909
  • 1
  • 10
  • 21
  • https://stackoverflow.com/a/36496683/3635454 – pleft Sep 14 '17 at 06:44
  • Possible duplicate of [One logfile per run with log4j](https://stackoverflow.com/questions/19132433/one-logfile-per-run-with-log4j) – pleft Sep 14 '17 at 06:45

1 Answers1

1

sounds like you donot need ROTATE file appender.

in your situation, i will advise you just use normarl file appender, this will make all log records into one file. all you need to do is name it by date pattern, like "yyyy-MM-dd.log".

ps: if you want rotate, logrorate tool on linux is a good choice too.

toien
  • 288
  • 3
  • 11