log4j的配置

发布于 2024-10-03 08:55:37 字数 1120 浏览 0 评论 0原文

我想基于 slf4jlog4j 配置我的日志系统。我想记录来自 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

云淡月浅 2024-10-10 08:55:37

您的配置文件编写不正确。
Appender 不应该是类/包减速,而是您想要将消息输出到的附加程序类型(如果您希望输出到默认附加程序,请将其留空)
该文件应该看起来更像:

log4j.rootLogger=FATAL 
log4j.logger.com.A=DEBUG

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:

log4j.rootLogger=FATAL 
log4j.logger.com.A=DEBUG
倒带 2024-10-10 08:55:37

您的文件格式是否不正确?您发布的内容看起来已损坏。我添加了一些换行符:

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

此外,这一行似乎是错误的:

log4j.appender.A1=com.A

它需要指定真正的附加程序类的名称,例如

log4j.appender.A1=org.apache.log4j.ConsoleAppender

Is your file formatted incorrectly? What you posted looks broken. I put in some linebreaks:

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

Also this line seems wrong:

log4j.appender.A1=com.A

It needs to specify the name of a real appender class, like

log4j.appender.A1=org.apache.log4j.ConsoleAppender
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文