I am using log4j to show log in my java application. I use the DailyRolligFileAppender to rolling the log file. It works well until I do a manuel restart. I will lose the last log file when the application is restarted. log4j will take this file, overwrite it, put two line of log, then create a new file and write into. So I lose the last file.
For example : I have
App.log.2015-10-09
App.log.2015-10-10 (last restart)
App.log.2015-10-11
App.log.2015-10-12
Let's suppose that the last restart was in 2015-10-10. If i restart the app in
2015-10-12 , then log4j will overwrite the content of App.log.2015-10-10 file, writing into these lines :
App - 12 Oct2015 10:18:31,960 DEBUG -- [PropertyMessageResources]
App - 12 Oct 2015 10:18:31,972 DEBUG --[ActionServlet] Finalizing this controller servlet
App - 12 Oct 2015 10:18:31,977 INFO -- [GraniteConfigListener] GraniteDS stopped
Then it will close this file and create a new file normally named App.log
which will write the current log.
this is my log4j.xml :
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
<!-- ALL < DEBUG < INFO < WARN < ERROR < FATAL < OFF -->
<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/"
debug="false">
<!-- ********** APPENDERS DEFINITION (begin) ********** -->
<appender name="exp_FILE_APPENDER" class="org.apache.log4j.DailyRollingFileAppender">
<param name="File" value="/data1/nom_app/logs/app.log" />
<param name="Append" value="true" />
<param name="DatePattern" value=".yyyy-MM-dd-HH-mm" />
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern"
value="nom_app - %d{DATE} %-5p %X{Batch}-%X{idSession}-%X{idRequete} [%c{1}] %m%n" />
</layout>
</appender>
<!-- Delia -->
<logger name="nom_package">
<level value="DEBUG" />
</logger>
<!-- appender -->
<root>
<level value="DEBUG" />
<appender-ref ref="exp_FILE_APPENDER" />
</root>
</log4j:configuration>
Can you please tell me how should I do to avoid the lose of the log file.