eclipse Log4j 未使用属性文件找到自定义 appender
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3978918/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Log4j not finding custom appender using a property file
提问by Protostome
I'm trying to configure log4j in an Eclipse plugin project using the following XML property file, that includes a custom appender called EclipseLoggingAppender:
我正在尝试使用以下 XML 属性文件在 Eclipse 插件项目中配置 log4j,其中包括一个名为 EclipseLoggingAppender 的自定义 appender:
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/" debug="true">
<appender name="eclipseErrorView" class="com.lior.ibd.utils.logging.EclipseLoggingAppender"/>
<appender name="console" class="org.apache.log4j.ConsoleAppender">
<param name="Target" value="System.out"/>
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%-5p %c{1} - %m%n"/>
</layout>
</appender>
<root>
<priority value ="debug" />
<appender-ref ref="console" />
</root>
<logger name="com.lior">
<level value ="warn" />
<appender-ref ref="eclipseErrorView" />
</logger>
</log4j:configuration>
I pass this property file to the following statement in the code:
我将此属性文件传递给代码中的以下语句:
DOMConfigurator.configure(filename);
But when loading the application I get the following error message:
但是在加载应用程序时,我收到以下错误消息:
log4j:ERROR Could not create an Appender. Reported error follows.
java.lang.ClassNotFoundException: com.lior.ibd.utils.logging.EclipseLoggingAppender
Anyone knows what's the deal? could be a classpath issue?..
有谁知道是什么交易?可能是类路径问题?...
采纳答案by krtek
Yes, this is a classpath issue. Log4j is looking for class com.lior.ibd.utils.logging.EclipseLoggingAppender. (probably appender that wrote someone in your organisation?)
是的,这是一个类路径问题。Log4j 正在寻找类 com.lior.ibd.utils.logging.EclipseLoggingAppender。(可能是在您的组织中写过某人的附加程序?)
If you remove lines:
如果删除行:
<appender name="eclipseErrorView" class="com.lior.ibd.utils.logging.EclipseLoggingAppender"/>
and
和
<logger name="com.lior">
<level value ="warn" />
<appender-ref ref="eclipseErrorView" />
</logger>
log4j should handle it.
log4j 应该处理它。
Or add EclipseLoggingAppender to classpath by locating a appropriate jar file and add it to the classpath. I.e. run
或者通过找到适当的 jar 文件并将其添加到类路径,将 EclipseLoggingAppender 添加到类路径。即运行
java -cp appender.jar com.mypackage.MyClass
回答by Brad Mace
for starters you can only have one <root>
element. You want something more like
对于初学者,您只能拥有一个<root>
元素。你想要更像
<appender name="eclipseErrorView" class="com.mypackage.EclipseLoggingAppender">
<filter class="org.apache.log4j.varia.LevelRangeFilter Source code of org.apache.log4j.varia.LevelRangeFilter">
<param name="LevelMin" value="WARN" />
</filter>
</appender>
<root>
<priority value ="debug" />
<appender-ref ref="console" />
<appender-ref ref="eclipseErrorView" />
</root>
How have you added your custom logger to the classpath?
您是如何将自定义记录器添加到类路径的?