0

I am developing a java web application using eclipse IDE and jboss server (version 5). I am trying to implement a custom log file for my application with the following code :

FileAppender fileAppender=new FileAppender(newPatternLayout(),Constant.LOGGER_PATH);
logger.addAppender(fileAppender);
BasicConfigurator.configure();
logger.setLevel(Level.ERROR);
logger.error(cause);

When I am trying to deploy my application to the jboss server it gives following exception :

    18:35:16,346 ERROR [STDERR] log4j:ERROR A "org.jboss.logging.util.OnlyOnceError
    andler" object is not assignable to a "org.apache.log4j.spi.ErrorHandler" varia
    le.
    18:35:16,346 ERROR [STDERR] log4j:ERROR The class "org.apache.log4j.spi.ErrorHa
    dler" was loaded by
    18:35:16,346 ERROR [STDERR] log4j:ERROR [WebappClassLoader
      delegate: false
      repositories:
        /WEB-INF/classes/
    ----------> Parent Classloader:
    java.net.FactoryURLClassLoader@893918
    ] whereas object of type
    18:35:16,346 ERROR [STDERR] log4j:ERROR "org.jboss.logging.util.OnlyOnceErrorHa
    dler" was loaded by [org.jboss.system.server.NoAnnotationURLClassLoader@a32b].
    18:35:16,377 ERROR [STDERR] log4j:ERROR Could not create an Appender. Reported
    rror follows.
    18:35:16,377 ERROR [STDERR] java.lang.ClassCastException: org.jboss.logging.app
    nder.DailyRollingFileAppender cannot be cast to org.apache.log4j.Appender
skaffman
  • 398,947
  • 96
  • 818
  • 769
Raktim
  • 91
  • 4
  • 9

1 Answers1

1

It looks like your application has its own copy of log4j.jar bundles into its lib directory. This will clash with JBoss's own copy.

Remove that JAR from the lib directory and try again, your app will use the JBoss copy.

skaffman
  • 398,947
  • 96
  • 818
  • 769
  • Thanks for your suggestion, but due to some problem in the client's hosting server, no log data is printing on the server log. That's why I have to implement this Custom log file. Can I avoid this clash with the help of any code. If something is there, please help me. – Raktim May 17 '12 at 17:21
  • @user1401030: Your custom logger will still work when you take the log4j JAR out of the app. It will use JBoss's copy of the JAR. – skaffman May 18 '12 at 10:43
  • Thank a lot for your suggestion. It really helped me to overcome my problem. – Raktim May 21 '12 at 05:34