使用Log4j的步骤

1、加入log4j的jar包,

2、加入log4j.properties的日志文件    文件放在项目的resources文件夹下

### 设置###
log4j.rootLogger =INFO,stdout,D,E
 
### 输出信息到控制抬 ###
log4j.appender.stdout = org.apache.log4j.ConsoleAppender
log4j.appender.stdout.Threshold = DEBUG
log4j.appender.stdout.layout = org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern = [%-5p] %d{yyyy-MM-dd HH:mm:ss,SSS} method:%l%n%m%n
 
### 输出DEBUG 级别以上的日志到=E://logs/error.log ###
log4j.appender.D = org.apache.log4j.DailyRollingFileAppender
log4j.appender.D.File = c://create_jcwt_integration_logs/log.log
log4j.appender.D.Append = true
log4j.appender.d.Encoding=UTF-8 
log4j.appender.D.Threshold = DEBUG 
log4j.appender.D.layout = org.apache.log4j.PatternLayout
log4j.appender.D.layout.ConversionPattern = %-d{yyyy-MM-dd HH:mm:ss}  [ %t:%r ] - [ %p ]  %m%n
 
### 输出ERROR 级别以上的日志到=E://logs/error.log ###
log4j.appender.E = org.apache.log4j.DailyRollingFileAppender
log4j.appender.E.File =c://create_jcwt_integration_logs/error.log 
log4j.appender.E.Append = true
log4j.appender.E.Threshold = ERROR 
log4j.appender.e.Encoding=UTF-8 
log4j.appender.E.layout = org.apache.log4j.PatternLayout
log4j.appender.E.layout.ConversionPattern = %-d{yyyy-MM-dd HH:mm:ss}  [ %t:%r ] - [ %p ]  %m%n

3、使用log4j

private Logger logger = Logger.getLogger(HFCreateService.class);
logger.error(msg);

  

上一篇:Detected both log4j-over-slf4j.jar AND bound slf4j-log4j12.jar on the class path, preempting StackOv


下一篇:【log4j.properties配置完整版】