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 one. I do not have a Linux machine right now, so I'm not sure if it can resolve the performance issue.
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() {
if (qw == null) {
File logFile = new File(super.fileName);
if (!logFile.exists()) {
try {
logFile.createNewFile();
} catch (IOException e) {
System.out.println("Error while create new log file.");
}
}
}
}
}