0

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.

4

1 回答 1

0

我认为您在 Web 应用程序中使用 log4j,所以下面的方法可能会有所帮助:

编写一个jsp文件来重新配置log4j。把它放在 webapp flder 中。像这样:

重置.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");

/* 所有 log4j.properties 内容.. */

    org.apache.log4j.LogManager.resetConfiguration();
    org.apache.log4j.PropertyConfigurator.configure(pro);
%>

删除“/var/log/tomcat6/h3cloud.log”后,打开http: //*/reset.jsp,重新创建新的“/var/log/h3coud.log”。

于 2014-03-10T11:27:41.643 回答