添加SLF4J依赖,用于提供日志API, 使用log4j作为实现
1.pom.xml添加SLF4J依赖
1 <!-- SLF4J --> 2 <dependency> 3 <groupId>org.slf4j</groupId> 4 <artifactId>slf4j-log4j12</artifactId> 5 <version>1.7.7</version> 6 </dependency>
2.在main/resources目录下创建log4j.properties
1 og4j.rootLogger = DEBUG,console,file 2 3 log4j.appender.console=org.apache.log4j.ConsoleAppender 4 log4j.appender.console.layout=org.apache.log4j.PatternLayout 5 log4j.appender.console.layout.ConversionPattern=%m%n 6 7 log4j.appender.file = org.apache.log4j.DailyRollingFileAppender 8 log4j.appender.file.File = ${user.home}/logs/book.log 9 log4j.appender.file.DatePattern = '_'yyyy-MM-dd 10 log4j.appender.file.layout = org.apache.log4j.PatternLayout 11 log4j.appender.file.layout.ConversionPattern =%d{yyyy-MM-dd HH:mm:ss,SSS} %p %c {%L} -%m%n 12 13 log4j.logger.cn.burgundyred=DEBUG # 指定日志作用位置
1. 日志级别
1) ERROR > WARN > INFO > DEBUG
2) 级别大于等于设置的级别, 该级别的日志就会被输出, 例如设置成WARN, 则输出DEBUG和WARN, 设置成DEBUG, 则只输出DEBUG
2. 日志appender
console
file