How to configure log4j to Auto create application log files when deleted manually without restarting the server? Currently we have to restart the server if someone deletes the log files.We are using websphere application server.
Asked
Active
Viewed 1,708 times
0
-
duplicate : http://stackoverflow.com/questions/12106258/log4j-fileappender-recreating-deleted-files – Anil Feb 17 '13 at 07:25
-
Thanks Anil. Actually I was looking for log4j level configuration instead of writing some implementation as suggested in the post link shared by you but I think this the only way to do it. – Harshit Feb 17 '13 at 09:15
1 Answers
0
I think you are using log4j in web application, so maybe the method below may be helpful:
write a jsp file to reconfigure the log4j. put it in webapp floder. just like this:
reset.jsp
<%
java.util.Properties pro = new java.util.Properties();
pro.put("log4j.appender.A1.Threshold","INFO");
pro.put("log4j.appender.A1","org.apache.log4j.RollingFileAppender");
pro.put("log4j.appender.A1.File","/var/log/h3cloud.log");
pro.put("log4j.appender.A1.MaxFileSize","100000KB");
pro.put("log4j.appender.A1.MaxBackupIndex","5");
/* all the log4j.properties content.. */
org.apache.log4j.LogManager.resetConfiguration();
org.apache.log4j.PropertyConfigurator.configure(pro);
%>
After I deleted the "/var/log/tomcat6/h3cloud.log", I open http://*/reset.jsp, the new "/var/log/h3coud.log" is recreated.

user987339
- 10,519
- 8
- 40
- 45

meng
- 105
- 6