logging-log4j-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Tom Hsu <tom....@oracle.com>
Subject Log4J exception
Date Tue, 04 Nov 2008 19:32:55 GMT
Hi experts,

I am using a an xml document to configure the Log4j from apache. 
However, I am seeing an class cast exception when I try to run my Java 
program which configures the log4j through a xml document. The trace is 
attached. I don't understand the following 2 errors:
1. java.lang.ClassCastException: org.apache.log4j.ConsoleAppender cannot 
be cast to org.apache.log4j.Appender
2.log4j:ERROR Could not parse input source 
[org.xml.sax.InputSource@200db9].
java.lang.NullPointerException

I am sure that the xml is well-formed because I was able to use that xml 
in an existing system. I have also attached the xml config file. If 
anyone can provide some pointers, it'd be greatly appreciated!

StackTrace
***
log4j:ERROR Could not create an Appender. Reported error follows.
java.lang.ClassCastException: org.apache.log4j.ConsoleAppender cannot be 
cast to org.apache.log4j.Appender
   at 
org.apache.log4j.xml.DOMConfigurator.parseAppender(DOMConfigurator.java:165) 

   at 
org.apache.log4j.xml.DOMConfigurator.findAppenderByName(DOMConfigurator.java:140) 

   at 
org.apache.log4j.xml.DOMConfigurator.findAppenderByReference(DOMConfigurator.java:153) 

   at 
org.apache.log4j.xml.DOMConfigurator.parseChildrenOfLoggerElement(DOMConfigurator.java:415)


   at 
org.apache.log4j.xml.DOMConfigurator.parseRoot(DOMConfigurator.java:384)
   at org.apache.log4j.xml.DOMConfigurator.parse(DOMConfigurator.java:783)
   at 
org.apache.log4j.xml.DOMConfigurator.doConfigure(DOMConfigurator.java:666)
   at 
org.apache.log4j.xml.DOMConfigurator.doConfigure(DOMConfigurator.java:616)
   at 
org.apache.log4j.xml.DOMConfigurator.doConfigure(DOMConfigurator.java:584)
   at org.apache.log4j.xml.XMLWatchdog.doOnChange(DOMConfigurator.java:815)
   at 
org.apache.log4j.helpers.FileWatchdog.checkAndConfigure(FileWatchdog.java:80) 

   at org.apache.log4j.helpers.FileWatchdog.<init>(FileWatchdog.java:49)
   at org.apache.log4j.xml.XMLWatchdog.<init>(DOMConfigurator.java:807)
   at 
org.apache.log4j.xml.DOMConfigurator.configureAndWatch(DOMConfigurator.java:574) 

   at 
org.apache.log4j.xml.DOMConfigurator.configureAndWatch(DOMConfigurator.java:557) 

    ...
log4j:ERROR Could not parse input source [org.xml.sax.InputSource@200db9].
java.lang.NullPointerException
   at java.util.Hashtable.put(Unknown Source)
   at 
org.apache.log4j.xml.DOMConfigurator.findAppenderByName(DOMConfigurator.java:141) 

   at 
org.apache.log4j.xml.DOMConfigurator.findAppenderByReference(DOMConfigurator.java:153) 

   at 
org.apache.log4j.xml.DOMConfigurator.parseChildrenOfLoggerElement(DOMConfigurator.java:415)


   at 
org.apache.log4j.xml.DOMConfigurator.parseRoot(DOMConfigurator.java:384)
   at org.apache.log4j.xml.DOMConfigurator.parse(DOMConfigurator.java:783)
   at 
org.apache.log4j.xml.DOMConfigurator.doConfigure(DOMConfigurator.java:666)
   at 
org.apache.log4j.xml.DOMConfigurator.doConfigure(DOMConfigurator.java:616)
   at 
org.apache.log4j.xml.DOMConfigurator.doConfigure(DOMConfigurator.java:584)
   at org.apache.log4j.xml.XMLWatchdog.doOnChange(DOMConfigurator.java:815)
   at 
org.apache.log4j.helpers.FileWatchdog.checkAndConfigure(FileWatchdog.java:80) 

   at org.apache.log4j.helpers.FileWatchdog.<init>(FileWatchdog.java:49)
   at org.apache.log4j.xml.XMLWatchdog.<init>(DOMConfigurator.java:807)
   at 
org.apache.log4j.xml.DOMConfigurator.configureAndWatch(DOMConfigurator.java:574) 

   at 
org.apache.log4j.xml.DOMConfigurator.configureAndWatch(DOMConfigurator.java:557) 

   ...
***

XML Config file
***
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/">
 <appender name="NullAppender" class="org.apache.log4j.varia.NullAppender">
 </appender>

 <appender name="AGENTFILE" class="org.apache.log4j.RollingFileAppender">
   <param name="File" value="./jagent/agent.log"/>
   <param name="Append" value="false"/>
   <param name="MaxFileSize" value="500KB"/>
   <param name="MaxBackupIndex" value="1"/>
   <param name="Threshold" value="DEBUG"/>
   <layout class="org.apache.log4j.PatternLayout">
     <param name="ConversionPattern" value="%d{yyyy-MM-dd HH:mm:ss} %-5p 
[%t][%c] %m%n"/>
   </layout>        </appender>

 <appender name="CONSOLE" class="org.apache.log4j.ConsoleAppender">
   <param name="Threshold" value="DEBUG"/>
   <param name="Target" value="System.out"/>

   <layout class="org.apache.log4j.PatternLayout">
     <!-- The default pattern: Date Priority [Category] Message\n -->
     <param name="ConversionPattern" value="%d{ABSOLUTE} %-5p [%c{1}] 
%m%n"/>
   </layout>
 </appender>

 <root>
   <priority value="WARN"/>
   <appender-ref ref="CONSOLE" />
 </root>

</log4j:configuration>
***


Regards,
Tom

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message