log4j.properties 配置详解
1、日志级别
Log4j日志级别,分OFF、FATAL、ERROR、WARN、INFO、DEBUG、ALL
2、配置文件log4j.properties
//ERROR:日志级别
//debug,error,Console:日志输出类型
log4j.rootLogger=ERROR,debug,error,Console,File
//打印日志
log4j.appender.Console = org.apache.log4j.ConsoleAppender
log4j.appender.Console.Target = System.out
log4j.appender.Console.ImmediateFlush = true
log4j.appender.Console.layout = org.apache.log4j.PatternLayout
log4j.appender.Console.layout.ConversionPattern = [%p][%-d{yyyy-MM-dd HH:mm:ss}] %m %n
//输出到日志文件
log4j.appender.debug=org.apache.log4j.DailyRollingFileAppender
log4j.appender.debug.layout=org.apache.log4j.PatternLayout
log4j.appender.debug.layout.ConversionPattern=[%-5p] [%d{HH:mm:ss}] %c - %m%n
log4j.appender.debug.datePattern='.'yyyy-MM-dd
//Threshold: 阀值; 级别大于等于该值时才输出
log4j.appender.debug.Threshold=INFO
log4j.appender.debug.append=true
log4j.appender.debug.File=logs/web.info.log
//输出到日志文件
log4j.appender.error=org.apache.log4j.DailyRollingFileAppender
log4j.appender.error.layout=org.apache.log4j.PatternLayout
log4j.appender.error.layout.ConversionPattern=[%-5p] [%d{HH:mm:ss}]%l - %m%n
log4j.appender.error.datePattern='.'yyyy-MM-dd
//Threshold: 阀值; 级别大于等于该值时才输出
log4j.appender.error.Threshold=ERROR
log4j.appender.error.append=true
log4j.appender.error.File=logs/web.error.log
//输出到日志文件
log4j.appender.File = org.apache.log4j.DailyRollingFileAppender
log4j.appender.File.layout = org.apache.log4j.PatternLayout
log4j.appender.File.layout.ConversionPattern =[%-5p] [%d{HH:mm:ss}]%l - %m%n
//Threshold: 阀值; 级别大于等于该值时才输出
log4j.appender.File.Threshold=ERROR
log4j.appender.File.append=true
log4j.appender.File.File = logs/web.file.log
//包级别设置日志级别,rootLogger设置失效
log4j.logger.com.web=INFO
log4j.logger.org.apache.commons.beanutils=ERROR
log4j.logger.org.apache.http=ERROR