This discussion is archived
4 Replies Latest reply: Nov 16, 2012 9:45 AM by 927628 RSS

cannot be cast to org.apache.log4j.Appender

963308 Newbie
Currently Being Moderated
Hello to all,
I have the following problem.
I created a class called myLogger that extends the object of Log4J Appender.
Unfortunately, no matter what I do (access to the console or a simple servlet) I always get the same problem.
I can not figure out what it is.

java.lang.ClassCastException: it.log.MyLogger 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.parseCategory(DOMConfigurator.java:335)
     at org.apache.log4j.xml.DOMConfigurator.parse(DOMConfigurator.java:781)
     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:602)
     at org.apache.log4j.helpers.OptionConverter.selectAndConfigure(OptionConverter.java:460)
     at org.apache.log4j.LogManager.<clinit>(LogManager.java:113)
     at org.apache.log4j.Logger.getLogger(Logger.java:85)
     at org.apache.commons.logging.impl.Log4JLogger.getLogger(Log4JLogger.java:229)
     at org.apache.commons.logging.impl.Log4JLogger.<init>(Log4JLogger.java:65)
     at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
     at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
     at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
     at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
     at org.apache.commons.logging.impl.LogFactoryImpl.newInstance(LogFactoryImpl.java:529)
     at org.apache.commons.logging.impl.LogFactoryImpl.getInstance(LogFactoryImpl.java:235)
     at org.apache.commons.logging.impl.LogFactoryImpl.getInstance(LogFactoryImpl.java:209)
     at org.apache.commons.logging.LogFactory.getLog(LogFactory.java:351)
     at com.bea.console.resource.http.ResourceServlet.<clinit>(ResourceServlet.java:54)
     at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
     at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
     at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
     at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
     at java.lang.Class.newInstance0(Class.java:355)
     at java.lang.Class.newInstance(Class.java:308)
     at weblogic.servlet.internal.WebComponentContributor.getNewInstance(WebComponentContributor.java:225)
     at weblogic.servlet.internal.WebComponentContributor.createServletInstance(WebComponentContributor.java:249)
     at weblogic.servlet.internal.StubSecurityHelper$ServletInitAction.run(StubSecurityHelper.java:255)
     at weblogic.security.acl.internal.AuthenticatedSubject.doAs(AuthenticatedSubject.java:321)
     at weblogic.security.service.SecurityManager.runAs(SecurityManager.java:120)
     at weblogic.servlet.internal.StubSecurityHelper.createServlet(StubSecurityHelper.java:64)
     at weblogic.servlet.internal.StubLifecycleHelper.createOneInstance(StubLifecycleHelper.java:58)
     at weblogic.servlet.internal.StubLifecycleHelper.<init>(StubLifecycleHelper.java:48)
     at weblogic.servlet.internal.ServletStubImpl.prepareServlet(ServletStubImpl.java:539)
     at weblogic.servlet.internal.WebAppServletContext.preloadServlet(WebAppServletContext.java:1985)
     at weblogic.servlet.internal.WebAppServletContext.loadServletsOnStartup(WebAppServletContext.java:1959)
     at weblogic.servlet.internal.WebAppServletContext.preloadResources(WebAppServletContext.java:1878)
     at weblogic.servlet.internal.WebAppServletContext.start(WebAppServletContext.java:3153)
     at weblogic.servlet.internal.WebAppModule.startContexts(WebAppModule.java:1508)
     at weblogic.servlet.internal.WebAppModule.start(WebAppModule.java:482)
     at weblogic.application.internal.flow.ModuleStateDriver$3.next(ModuleStateDriver.java:425)
     at weblogic.application.utils.StateMachineDriver.nextState(StateMachineDriver.java:52)
     at weblogic.application.internal.flow.ModuleStateDriver.start(ModuleStateDriver.java:119)
     at weblogic.application.internal.flow.ScopedModuleDriver.start(ScopedModuleDriver.java:200)
     at weblogic.application.internal.flow.ModuleListenerInvoker.start(ModuleListenerInvoker.java:247)
     at weblogic.application.internal.flow.ModuleStateDriver$3.next(ModuleStateDriver.java:425)
     at weblogic.application.utils.StateMachineDriver.nextState(StateMachineDriver.java:52)
     at weblogic.application.internal.flow.ModuleStateDriver.start(ModuleStateDriver.java:119)
     at weblogic.application.internal.flow.StartModulesFlow.activate(StartModulesFlow.java:27)
     at weblogic.application.internal.BaseDeployment$2.next(BaseDeployment.java:636)
     at weblogic.application.utils.StateMachineDriver.nextState(StateMachineDriver.java:52)
     at weblogic.application.internal.BaseDeployment.activate(BaseDeployment.java:205)
     at weblogic.application.internal.EarDeployment.activate(EarDeployment.java:58)
     at weblogic.application.internal.BackgroundDeploymentService$2.next(BackgroundDeploymentService.java:373)
     at weblogic.application.utils.StateMachineDriver.nextState(StateMachineDriver.java:52)
     at weblogic.application.internal.BackgroundDeploymentService$BackgroundDeployAction.run(BackgroundDeploymentService.java:277)
     at weblogic.application.internal.BackgroundDeploymentService$OnDemandBackgroundDeployAction.run(BackgroundDeploymentService.java:336)
     at weblogic.work.SelfTuningWorkManagerImpl$WorkAdapterImpl.run(SelfTuningWorkManagerImpl.java:528)
     at weblogic.work.ExecuteThread.execute(ExecuteThread.java:209)
     at weblogic.work.ExecuteThread.run(ExecuteThread.java:178)
log4j:ERROR Could not parse input source [org.xml.sax.InputSource@4eef9712].
java.lang.NullPointerException
     at java.util.Hashtable.put(Hashtable.java:394)
     at org.apache.log4j.xml.DOMConfigurator.findAppenderByName(DOMConfigurator.java:141)
     at org.apache.log4j.xml.DOMConfigurator.findAppenderByReference(DOMConfigurator.java:153)

Can you help me?
Thanks
Vincenzo

Edited by: 960305 on Sep 20, 2012 3:26 AM
  • 1. Re: cannot be cast to org.apache.log4j.Appender
    Kalyan Pasupuleti-Oracle Expert
    Currently Being Moderated
    Hi,

    Please check whether you have any duplicate log4j.jar's in system environment which is not supported and trows following exception.

    Regards,
    Kal
  • 2. Re: cannot be cast to org.apache.log4j.Appender
    963308 Newbie
    Currently Being Moderated
    Hello,
    i have check all log4j.jar on my Weblogic but i have only one file.
    I do not understand what could be the problem.
  • 3. Re: cannot be cast to org.apache.log4j.Appender
    Kalyan Pasupuleti-Oracle Expert
    Currently Being Moderated
    Hi,

    check by clearing cache and tmp folder with in specific server and try one more time.

    Regards,
    kal
  • 4. Re: cannot be cast to org.apache.log4j.Appender
    927628 Newbie
    Currently Being Moderated
    I'm getting the exact same thing.

    Here's the steps I took:

    *1. Copied server log4j logs to DOMAIN_HOME/lib:*
    cp ./wlserver_10.3/server/lib/wllog4j.jar user_projects/domains/my_domain/lib/
    cp ./wlserver_10.3/server/lib/consoleapp/APP-INF/lib/log4j-1.2.8.jar user_projects/domains/my_domain/lib/

    *2. Created log4j.xml file where I created a new appender:*

    <appender name="WEBLOGIC" class="weblogic.logging.log4j.ServerLoggingAppender">
    <param name="Threshold" value="ERROR"/>
    </appender>

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

    *3. Updated the ${DOMAIN_HOME}/bin/setDomainEnv.sh script with these changes:*

    LOG4J_CONFIG_FILE="${DOMAIN_HOME}/config/log4j.xml"
    if [ "${LOG4J_CONFIG_FILE}" != "" ] ; then
    JAVA_PROPERTIES="${JAVA_PROPERTIES} Dlog4j.configuration=file:${LOG4J_CONFIG_FILE}"
    export JAVA_PROPERTIES
    fi

    JAVA_OPTIONS="${JAVA_OPTIONS} ${JAVA_PROPERTIES} -Dweblogic.log.Log4jLoggingEnabled=true -Dwlw.iterativeDev=${iterativeDevFlag} -Dwlw.testConsole=${testConsoleFlag} -Dwlw.logErrorsToConsole=${logErrorsToConsoleFlag}"

    *4. Starts the AdminServer, but I get this error:*

    java.lang.ClassCastException: weblogic.logging.log4j.ServerLoggingAppender cannot be cast to org.apache.log4j.Appender

Legend

  • Correct Answers - 10 points
  • Helpful Answers - 5 points