每日学习笔记(21)
1,今天收到报警信息,说应用所在机器的硬盘空间不足了,上去一看,居然发现国庆这几天的日志信息累计达到了260多G,可看了下应用下的日志,实际只有几十M而已,进一步check后发现是调用的第三方应用在另一个日志路径下打出大量的Debug信息,回查代码后才明白是Logback和Log4J的冲突问题,于是写了一个类在应用启动时将Log4J的级别调高至ERROR级别,代码如下:
privatestatic String logFilePath;
private final static String DEFAULT_LOG4J_FILE_NAME = "log4j.xml";
private org.slf4j.Logger log = org.slf4j.LoggerFactory.getLogger(getClass());
private void configureLog4j() throws javax.xml.parsers.FactoryConfigurationError {
System.setProperty( "org.apache.commons.logging.Log", "org.apache.commons.logging.impl.NoOpLog" );
Properties p = new Properties();
p.put("log4j.logger.httpclient.wire", Level.ERROR);
p.put("log4j.logger.org.apache.commons.httpclient", Level.ERROR);
Logger root = Logger.getRootLogger();
boolean rootIsConfigured = root.getAllAppenders().
hasMoreElements();
if(root != null) {
root.setLevel(Level.ERROR);
}
log.error("turn off log4j");
}
public static String getLogFilePath() {
return logFilePath;
}
public static void setLogFilePath(String logFilePath) {
Log4jInit.logFilePath = logFilePath;
}
}
作者:洞庭散人
出处:http://phinecos.cnblogs.com/
posted on 2011-10-12 19:50 Phinecos(洞庭散人) 阅读(1098) 评论(0) 编辑 收藏 举报