Q:Failed to load class "org.slf4j.impl.StaticLoggerBinder"
控制台显示如图
A:在项目所在的maven工程的pom文件中添加如下依赖(PS:版本号可以根据slf4j-api 依赖的版本来配置)
<!-- https://mvnrepository.com/artifact/org.slf4j/slf4j-log4j12 -->
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>1.7.25</version>
</dependency>
Q:WARN? no appenders could be found for logger
控制台显示如图
A:在项目所在的resource目录下,添加log4j.properties配置文件
log4j.rootLogger=DEBUG, stdout, #日志级别设置 #log4j.rootLogger=WARN, stdout, #log4j.rootLogger=INFO,stdout,file,R 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{yyyy-MM-dd HH:mm:ss,SSS} [%t] [%c] [%p] - %m%n log4j.appender.file = org.apache.log4j.FileAppender log4j.appender.file.File = 日志在系统中输入目录 log4j.appender.file.layout=org.apache.log4j.PatternLayout log4j.appender.file.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss,SSS} [%t] [%c] [%p] - %m%n log4j.appender.R=org.apache.log4j.DailyRollingFileAppender log4j.appender.R.File= 日志在系统中输入目录 log4j.appender.R.layout=org.apache.log4j.PatternLayout log4j.appender.R.layout.ConversionPattern=%d-[TS] %p %t %c - %m%n