log4j即使已经定义了logger,也无法找到记录器的appender
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了log4j即使已经定义了logger,也无法找到记录器的appender相关的知识,希望对你有一定的参考价值。
My Log4j.xml file ( log4j 1.2.15)
<appender name="Append1" class="org.apache.log4j.FileAppender">
<param name="File" value="tomcat/log.out"/>
<param name="Append" value="true"/>
<param name="Threshold" value="DEBUG"/>
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%d %-5p [%c] (%t) %m%n"/>
</layout>
</appender>
logger level :
<logger name="xx.yy.zzzz.Controller" additivity="false">
<level value="DEBUG"/>
<appender-ref ref="Append1"/>
</logger>
Log in catalina file :
log4j: Setting property [file] to [/log.out].
log4j: Setting property [append] to [true].
log4j: Setting property [threshold] to [DEBUG].
log4j: Parsing layout of class: "org.apache.log4j.PatternLayout"
log4j: Setting property [conversionPattern] to [%d %-5p [%c] (%t) %m%n].
log4j: setFile called: log.out, true
log4j: setFile ended
log4j: Retreiving an instance of org.apache.log4j.Logger.
log4j: Setting [xx.yy.zzzz.Controller] additivity to [false].
log4j: Level value for xx.yy.zzzz.Controller is [DEBUG].
log4j: **xx.yy.zzzz.Controller level set to DEBUG**
log4j: Adding appender named [Append1] to category [xx.yy.zzzz.Controller].
我们有此警告消息,我们没有跟踪
log4j:WARN No appenders could be found for logger (xx.yy.zzzz.Controller).
log4j:WARN Please initialize the log4j system properl
和。
java类:
public final class Controller {
private static Logger LOGGER = Logger.getLogger(Controller.class);
public method1(){
LOGGER.debug("test")
}
}
答案
看来你刚刚拼错了记录器名称的情况
<logger name="xx.yy.zzzz.Controller" additivity="false">
...
</logger>
“控制器”是大写字母
以上是关于log4j即使已经定义了logger,也无法找到记录器的appender的主要内容,如果未能解决你的问题,请参考以下文章
换掉 Log4j2..tinylog 横空出世,无需定义 logger 变量,简单轻量性能爆炸。。
Java日志框架 -- LOG4J(Log4j入门案例日志级别Log4j组件(LoggersAppendersLayouts)配置文件内置日志记录自定义Logger)