log4j的配置
我想基于 slf4j 和 log4j 配置我的日志系统。我想记录来自 com.A 类的所有消息。并且只有那些消息。
所以我在我的配置文件中写道
log4j.rootLogger=FATAL, All log4j.rootLogger=DEBUG, A1 log4j.appender.A1=com.A log4j.appender.Console=org.apache.log4j.ConsoleAppender log4j.appender.Console.layout=org.apache.log4j.PatternLayout log4j.appender.Console.layout.conversionPattern=%m%n
我的跑步者(com.Start 类)包含
PropertyConfigurator.configure("log4j.properties");
但是当我启动应用程序时我得到了
log4j:ERROR A "com.A" object is not assignable to a "org.apache.log4j.Appender" variable.
log4j:ERROR The class "org.apache.log4j.Appender" was loaded by
log4j:ERROR [sun.misc.Launcher$AppClassLoader@d9f9c3] whereas object of type
log4j:ERROR "com.A" was loaded by [sun.misc.Launcher$AppClassLoader@d9f9c3].
log4j:ERROR Could not instantiate appender named "A1".
log4j:WARN No appenders could be found for logger (com.Start).
log4j:WARN Please initialize the log4j system properly.
log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.
我的错误在哪里?
谢谢。
I want to config my logging system based on slf4j and log4j. I want to log all messages from com.A class. And only those messages.
so I wrote in my config file
log4j.rootLogger=FATAL, All log4j.rootLogger=DEBUG, A1 log4j.appender.A1=com.A log4j.appender.Console=org.apache.log4j.ConsoleAppender log4j.appender.Console.layout=org.apache.log4j.PatternLayout log4j.appender.Console.layout.conversionPattern=%m%n
My runner (com.Start class) contains
PropertyConfigurator.configure("log4j.properties");
But when I start application I get
log4j:ERROR A "com.A" object is not assignable to a "org.apache.log4j.Appender" variable.
log4j:ERROR The class "org.apache.log4j.Appender" was loaded by
log4j:ERROR [sun.misc.Launcher$AppClassLoader@d9f9c3] whereas object of type
log4j:ERROR "com.A" was loaded by [sun.misc.Launcher$AppClassLoader@d9f9c3].
log4j:ERROR Could not instantiate appender named "A1".
log4j:WARN No appenders could be found for logger (com.Start).
log4j:WARN Please initialize the log4j system properly.
log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.
Where's my error?
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您的配置文件编写不正确。
Appender 不应该是类/包减速,而是您想要将消息输出到的附加程序类型(如果您希望输出到默认附加程序,请将其留空)
该文件应该看起来更像:
Your configuration file isn't properly written.
Appender shouldn't be the class/package deceleration but a type of appender you would like to output messages to (leave it blank if you wish to output to the default appender)
The file should look more like:
您的文件格式是否不正确?您发布的内容看起来已损坏。我添加了一些换行符:
此外,这一行似乎是错误的:
它需要指定真正的附加程序类的名称,例如
Is your file formatted incorrectly? What you posted looks broken. I put in some linebreaks:
Also this line seems wrong:
It needs to specify the name of a real appender class, like