初用IDEA的springboot第五步
使用日志
先配置文件,在resources下新建一个log4j.properties,将以下内容粘贴进去
## 设置###stdout,
log4j.rootLogger = all,D,E,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 = [%-5p] %d{yyyy-MM-dd HH:mm:ss,SSS} method:%l%n%m%n
### 输出DEBUG 级别以上的日志到=D://logs/log.log ###
log4j.appender.D = org.apache.log4j.DailyRollingFileAppender
log4j.appender.D.File =D://logs/log.log
log4j.appender.D.Append = true
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://1ogs/error.log ###
log4j.appender.E = org.apache.log4j.DailyRollingFileAppender
log4j.appender.E.File =C://logs/error.log
log4j.appender.E.Append = true
log4j.appender.E,Threshold = ERROR
log4j.appender.E.layout = org.apache.log4j.PatternLayout
log4j.appender.E.layout.ConversionPattern = %-d{yyyy-MM-dd HH:mm:ss) [ %t:%r ]- [ %p ]
然后在里输入以下内容
//使用日志工厂类,记录日志
private Logger logger = LoggerFactory.getLogger(TestDB.class);
最后
运行后无红色报错即为成功