【转载】"No appenders could be found for logger"的错误

 

可能存在的情况:

(1)在tomcat\common\lib下多放了一个log4j,将其删除

That error is coming from commons-logging finding Log4j and using it in preference to j2sdk1.4.x 
logging, but if Log4j doesn't, then, find its configuration, you will get that error.

(2) 将log4j.properties所在的目录加到CLASSPATH中

(3)从WEB-INF\lib下复制log4j.jartomcat\common\lib

I just tested having log4j.jar in my WEB-INF/lib and not in common/lib and commons-logging in common/lib couldn't see it (and, therefore, didn't get the Log4j error), so it is most likely that you have log4j.jar in common/lib (or shared/lib) or some other place where commons-logging in Tomcat can see log4j.jar.        Remove Log4j.jar and you won't see that error....or, I suppose, you could add log4j.xml or log4j.properties to common/classes and all would be well.

(4)确认log4j.propertiestomcat\webapps\~\WEB-INF\classes下,~\src下,~\WebRoot\WEB-INF\classes

(5)一个多线程的程序,在子线程中会用到两个Logger,一个绑定到公共的日志输出,另一个则使用独立的日志文件,后者会在线程结束时关闭日志文件。开始我使用了Logger.shutdown(),正是这一方法导致了问题,原因在于shutdown会关闭所有在程序中使用到的Logger,甚至是RootLogger,同时释放Logger占用的所有资源,如Appender。这样一来自然其他的线程再向公共日志中输出时会报Appender不存在的错误。

             结论:如果希望显式地关闭日志,应该使用Appender.close()方法;对于FileAppender,可以使用CloseFile()方法。也可以直接使用Logger.removeAppender()方法强行移除Appender,但对于SocketAppender或AsyncAppender可能会导致pending logging。

(6)在 log4j.properties 中加入一个名为 org.springframework 的 Logger。例如:

log4j.logger.org.springframework=DEBUG, org.springframework, stdout
log4j.appender.org.springframework
=org.apache.log4j.FileAppender
log4j.appender.org.springframework.File
=/opt/adstat/log/spring.log
log4j.appender.org.springframework.Encoding
=utf8
log4j.appender.org.springframework.layout
=org.apache.log4j.PatternLayout
log4j.appender.org.springframework.layout.ConversionPattern
=%-d{yyyy-MM-dd HH:mm:ss} [%c]-[%p] %m%n

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值