普通java项目报错,控制台如下

 

 

 

SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.

 

 

解决方法:

添加maven依赖

 <dependency>
            <groupId>log4j</groupId>
            <artifactId>log4j</artifactId>
            <version>1.2.17</version>
        </dependency>
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-log4j12</artifactId>
            <version>1.6.6</version>
        </dependency>

添加日志配置文件 log4j.properties

#根据需要修改日志级别
log4j.rootLogger=INFO, stdout, logfile
log4j.debug=true
log4j.additivity.org.apache=true

#控制台输出
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%d %p [%c] - %m%n

#Catalina日志
# Define all the appenders
log4j.appender.CATALINA=org.apache.log4j.DailyRollingFileAppender
log4j.appender.CATALINA.Append=true 
log4j.appender.CATALINA.Encoding=UTF-8 

# Roll-over the log once per day
log4j.appender.CATALINA.DatePattern='.'yyyy-MM-dd-HH'.log' 
log4j.appender.CATALINA.MAXFileSize = 20MB 
log4j.appender.CATALINA.layout = org.apache.log4j.PatternLayout 
log4j.appender.CATALINA.layout.ConversionPattern =%d{HH:mm:ss} %5p [%t] - %m%n 

#文件输出
#log4j.appender.logfile=org.apache.log4j.RollingFileAppender
log4j.appender.logfile=org.apache.log4j.DailyRollingFileAppender
log4j.appender.logfile.File=/logs/spider.log 
log4j.appender.logfile.DatePattern='.'yyyy-MM-dd-HH'.log'
#日志文件最大20M
log4j.appender.logfile.MaxFileSize=20MB
log4j.appender.logfile.MaxBackupIndex=5
log4j.appender.logfile.layout=org.apache.log4j.PatternLayout
log4j.appender.logfile.layout.ConversionPattern=%d %p [%c] - %m%n


#logger
log4j.logger.org.springframework=DEBUG
log4j.logger.com.xxx=DEBUG
#log4j.logger.org.apache=DEBUG

log4j.logger.com.ibatis=DEBUG 
log4j.logger.com.ibatis.common.jdbc.SimpleDataSource=DEBUG 
log4j.logger.com.ibatis.common.jdbc.ScriptRunner=DEBUG 
log4j.logger.com.ibatis.sqlmap.engine.impl.SqlMapClientDelegate=DEBUG 
log4j.logger.java.sql.Connection=DEBUG 
log4j.logger.java.sql.Statement=DEBUG 
log4j.logger.java.sql.PreparedStatement=DEBUG
log4j.logger.java.sql.ResultSet=DEBUG

#spring aop拦截方法,计算方法执行所耗时间
log4j.additivity.org.springframework.aop.interceptor.PerformanceMonitorInterceptor=false
log4j.logger.org.springframework.aop.interceptor.PerformanceMonitorInterceptor=TRACE

httpclient.wire.header=ERROR
httpclient.wire.content=ERROR
org.apache.commons.httpclient = ERROR
httpclient.wire = ERROR 

 

posted on 2019-09-05 10:04  你不知道的浪漫  阅读(3692)  评论(0编辑  收藏  举报