tags:

views:

1117

answers:

2

Hi there,

I created a webservice on axis2 and I used log4j for logging purposes. I'm getting the following error any time a request comes in for this WS:

log4j:ERROR A "org.apache.log4j.ConsoleAppender" object is not assignable to a "org.apache.log4j.Appender" variable.
log4j:ERROR The class "org.apache.log4j.Appender" was loaded by 
log4j:ERROR [org.apache.catalina.loader.StandardClassLoader@7f342545] whereas object of type 
log4j:ERROR "org.apache.log4j.ConsoleAppender" was loaded by [WebappClassLoader
  delegate: false
  repositories:
    /WEB-INF/classes/
----------> Parent Classloader:
org.apache.catalina.loader.StandardClassLoader@7f342545
].
log4j:ERROR Could not instantiate appender named "CONSOLE".
[ERROR] java.lang.NullPointerException

My log4j.properties is as follows:

log4j.rootCategory=INFO, CONSOLE
#log4j.rootCategory=INFO, CONSOLE, LOGFILE

# Set the enterprise logger priority to FATAL
log4j.logger.org.apache.axis2.enterprise=FATAL
log4j.logger.de.hunsicker.jalopy.io=FATAL
log4j.logger.httpclient.wire.header=FATAL
log4j.logger.org.apache.commons.httpclient=FATAL

# CONSOLE is set to be a ConsoleAppender using a PatternLayout.
log4j.appender.CONSOLE=org.apache.log4j.ConsoleAppender
log4j.appender.CONSOLE.layout=org.apache.log4j.PatternLayout
log4j.appender.CONSOLE.layout.ConversionPattern=[%p] %m%n

# LOGFILE is set to be a File appender using a PatternLayout.
log4j.appender.LOGFILE=org.apache.log4j.FileAppender
log4j.appender.LOGFILE.File=axis2.log
log4j.appender.LOGFILE.Append=true
log4j.appender.LOGFILE.layout=org.apache.log4j.PatternLayout
log4j.appender.LOGFILE.layout.ConversionPattern=%d [%t] %-5p %c %x - %m%n

and I have no other copies of log4j.properties anywhere in my aar.

Does anybody have any clue why I'm getting this initialization error?

Thanks in advance, PJ

+2  A: 

You are in Jar Hell. I suspect the problem is you have 2 or more versions of the log4j jar being loaded by two different classloaders. Once I had a similar problem, though it was a different error message. I did a scan and found 7 vevrsions of log4j on my machine. Yikes!

How to avoid it? Eliminate all but one of them.

It worked for me.

Cheeso
Hi! Thanks for your reply. I did have another version of log4j when I checked this, so I renamed it to a different name and restarted tomcat but I still have the same problem :( Anything else that you think I might need to restart/clean up?
poijoi
I would drop the oldest log4j jar file completely, keeping the latest and greatest in the classpath.
Adam Hawkes
A: 

I deleted the old jar and restarted the tomcat server. The error went away. Thanks for your help!

poijoi