log4j.rootLogger = INFO , info, warn, error, stdout ###控制台输出 log4j.appender.stdout = org.apache.log4j.ConsoleAppender log4j.appender.stdout.Target = System.out log4j.appender.stdout.layout = org.apache.log4j.PatternLayout log4j.appender.stdout.layout.ConversionPattern = %d{ABSOLUTE} %5p %c{1}:%L - %m%n ###info级别输出 log4j.logger.info = info log4j.appender.info = org.apache.log4j.DailyRollingFileAppender log4j.appender.info.File = ${webroot}/logs/convert_info.log log4j.appender.info.Append = true log4j.appender.info.Threshold = INFO log4j.appender.info.layout = org.apache.log4j.PatternLayout log4j.appender.info.layout.ConversionPattern = %-d{yyyy-MM-dd HH:mm:ss} [ %t:%r ] - [ %p ] %m%n log4j.appender.info.datePattern='.'yyyy-MM-dd log4j.appender.info.filter.infoFilter = org.apache.log4j.varia.LevelRangeFilter log4j.appender.info.filter.infoFilter.LevelMin=INFO log4j.appender.info.filter.infoFilter.LevelMax=INFO ###warn级别输出 log4j.logger.warn = warn log4j.appender.warn=org.apache.log4j.DailyRollingFileAppender log4j.appender.warn.File = ${webroot}/logs/convert_warn.log log4j.appender.warn.Append=true log4j.appender.warn.Threshold=WARN log4j.appender.warn.layout=org.apache.log4j.PatternLayout log4j.appender.warn.layout.ConversionPattern=%-d{yyyy-MM-dd HH:mm:ss} [ %t:%r ] - [ %p ] %m%n log4j.appender.warn.datePattern='.'yyyy-MM-dd log4j.appender.warn.filter.warnFilter=org.apache.log4j.varia.LevelRangeFilter log4j.appender.warn.filter.warnFilter.LevelMin=WARN log4j.appender.warn.filter.warnFilter.LevelMax=WARN ###error级别输出 log4j.logger.error = error log4j.appender.error = org.apache.log4j.DailyRollingFileAppender log4j.appender.error.File = ${webroot}/logs/convert_error.log log4j.appender.error.Append = true log4j.appender.error.Threshold = ERROR log4j.appender.error.layout = org.apache.log4j.PatternLayout log4j.appender.error.layout.ConversionPattern = %-d{yyyy-MM-dd HH:mm:ss} [ %t:%r ] - [ %p ] %m%n log4j.appender.error.datePattern='.'yyyy-MM-dd log4j.appender.error.filter.errorFilter=org.apache.log4j.varia.LevelRangeFilter log4j.appender.error.filter.errorFilter.LevelMin=ERROR log4j.appender.error.filter.errorFilter.LevelMax=ERROR
private void log4jInitialized(){ String log4jPath = ""; try { log4jPath = ApplicationInitListener.class.getResource("").toURI().getPath(); log4jPath = log4jPath.substring(0, log4jPath.indexOf("WEB-INF")) + "WEB-INF"; } catch (URISyntaxException e) { // TODO Auto-generated catch block e.printStackTrace(); } System.setProperty("webroot", log4jPath); }
在网站应用程序初始化时调用
public void contextInitialized(ServletContextEvent arg0) { /*初始化日志路径*/ log4jInitialized(); }