gpt4 book ai didi

java - log4j的配置

转载 作者:行者123 更新时间:2023-11-29 03:59:54 24 4
gpt4 key购买 nike

我想基于slf4jlog4j 配置我的日志系统。我想记录来自 com.A 类的所有消息。而且只有那些消息。

所以我在我的配置文件中写了

log4j.rootLogger=FATAL, Alllog4j.rootLogger=DEBUG, A1log4j.appender.A1=com.Alog4j.appender.Console=org.apache.log4j.ConsoleAppenderlog4j.appender.Console.layout=org.apache.log4j.PatternLayoutlog4j.appender.Console.layout.conversionPattern=%m%n

My runner (com.Start class) contains

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.

我的错误在哪里?

谢谢。

最佳答案

你的配置文件没有写好。
Appender 不应该是类/包减速,而是您希望将消息输出到的一种 appender(如果您希望输出到默认 appender,请将其留空)
该文件应该更像:

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

关于java - log4j的配置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4218083/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com