I have a web application in Tomcat that uses log4j for logging.
If I delete the log files while the web application is running the files are not recreated?
How can I
You can have a customized RollingFileAppender and check for file existence.
This code checks for file existence before every logging and creates the file if it is missing.
public class CustomRollingFileAppender extends RollingFileAppender {
// ... Constructor
@Override
public void append(LoggingEvent event) {
if (!new File(this.fileName).exists()) {
try {
setFile(this.fileName, fileAppend, bufferedIO, bufferSize);
} catch (IOException e) {
e.printStackTrace();
}
}
super.append(event);
}
}