I am using Log4j as logging framework in a project I am working on. I have the following situation: Log4j is configured to write the logs into a log file. At some point, thi
Try This Class
package wodong.test;
import java.io.File;
import java.io.IOException;
import org.apache.log4j.FileAppender;
import org.apache.log4j.spi.LoggingEvent;
public class LastFileAppender extends FileAppender {
@Override
public void append(LoggingEvent event) {
checkLogFileExist();
super.append(event);
}
private void checkLogFileExist(){
File logFile = new File(super.fileName);
if (!logFile.exists()) {
try {
logFile.createNewFile();
} catch (IOException e) {
System.out.println("Error while create new log file.");
}
}
}
}
Also edit the log4j config file
log4j.appender.R=wodong.test.LastFileAppender