You are viewing a plain text version of this content. The canonical link for it is here.
Posted to log4j-user@logging.apache.org by Tom Hsu <to...@oracle.com> on 2008/11/04 20:32:55 UTC

Log4J exception

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

Re: Log4J exception

Posted by Tom Hsu <to...@oracle.com>.
Hi Curt,

Thanks for the suggestion. I am not familiar with class loaders so did 
not think it would be needed info.

Indeed, I am in an environment where multiple classloaders are probably 
used. Possibly since I am starting my main java program through 
Eclipse's equinox. Equinox provides a sophisticated bundling system 
which uses custom classloader for sure. With your pointer, I will have 
to dig further into Equinox bundle loading to see if a the log4j.jar is 
being loaded twice.

I am starting running the code through eclipse, and the main looks like 
this:
    public static void main(String[] args) {
        System.getProperties().put("JavaAgentLogConfigFile",
                "C:\\prototype\\log4j.xml");
        String[] launcherArgs = {
                "-configuration",
                "C:\\prototype\\configuration",
                "-install",
                "C:\\prototype",
                
"-DJavaAgentLogConfigFile=C:\\OracleATS2\\OFT\\jagent\\log4j-commandline.xml"};
        org.eclipse.core.launcher.Main.main(launcherArgs);
    }
The directory point to an instance of eclipse install. I am configuring 
this one since the eclipse environment has all the required plugins 
including the log4j bundles.

If anyone has some pointer on how to debug a environment like this, 
please let me know. I am just running this in eclipse debug mode.

Regards,
Tom

Curt Arnold wrote:
>
> On Nov 4, 2008, at 1:32 PM, Tom Hsu wrote:
>
>> 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!
>>
>
> You don't mention the environment that you are running the code in, 
> but it would appear that you have multiple class loaders and that is 
> causing the cast from ConsoleAppender to Appender to fail.  The 
> ClassCastException results in the NullPointerException that occurs 
> later.  Please check if you have multiple log4j.jar's in your 
> installation.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
> For additional commands, e-mail: log4j-user-help@logging.apache.org
>

---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-user-help@logging.apache.org


Re: Log4J exception

Posted by Curt Arnold <ca...@apache.org>.
On Nov 4, 2008, at 1:32 PM, Tom Hsu wrote:

> 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!
>

You don't mention the environment that you are running the code in,  
but it would appear that you have multiple class loaders and that is  
causing the cast from ConsoleAppender to Appender to fail.  The  
ClassCastException results in the NullPointerException that occurs  
later.  Please check if you have multiple log4j.jar's in your  
installation.


---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-user-help@logging.apache.org