本文介绍了Log4j没有找到使用属性文件的自定义appender的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图使用以下XML属性文件在Eclipse插件项目中配置log4j,该属性文件包括名为EclipseLoggingAppender的自定义appender:

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 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?..

推荐答案

是的,这是一个类路径问题。 Log4j正在寻找类com.lior.ibd.utils.logging.EclipseLoggingAppender。
(可能是在您的组织中写过某人的appender)?

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?)

如果您删除行:

 <appender name="eclipseErrorView" class="com.lior.ibd.utils.logging.EclipseLoggingAppender"/>

 <logger name="com.lior">
   <level value ="warn" /> 
   <appender-ref ref="eclipseErrorView" />
 </logger> 

log4j应该处理它。

log4j should handle it.

或者通过查找适当的jar文件并将其添加到类路径中,将EclipseLoggingAppender添加到类路径。即运行

Or add EclipseLoggingAppender to classpath by locating a appropriate jar file and add it to the classpath. I.e. run

java -cp appender.jar com.mypackage.MyClass

这篇关于Log4j没有找到使用属性文件的自定义appender的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-20 04:30