Log4j does not find custom appender using properties file

I am trying to configure log4j in an Eclipse plugin project using the following XML properties file, which includes the custom appender 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, the following error message appears:

 log4j:ERROR Could not create an Appender. Reported error follows. java.lang.ClassNotFoundException: com.lior.ibd.utils.logging.EclipseLoggingAppender 

Does anyone know what the deal is? maybe a classpath problem? ..

+6
java eclipse log4j
source share
2 answers

Yes, this is a class problem. Log4j is looking for the class com.lior.ibd.utils.logging.EclipseLoggingAppender. (probably the appender who wrote someone in your organization?)

If you delete the 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.

Or add EclipseLoggingAppender to the classpath by placing the corresponding jar file and add it to the classpath. That is mileage

 java -cp appender.jar com.mypackage.MyClass 
+1
source share

for starters, you can only have one <root> element. Do you want something more like

 <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 did you add your own registrar to the classpath?

+1
source share

All Articles