Diego Borda
Diego Borda

Reputation: 173

How to configure Log4j in a multi project maven

I have a maven war project which depends on an EJB maven project. The EJB project handles all business logic including DB access through Hibernate. Both projects are JEE6 and run on glassfish 3.1.2 using maven. I'm currently trying to configure Log4j to work (also log hibernate) in the scenario described. I have the following log4j.xml file in my ejb's src/main/resources folder (I'm that it is in the classpath):

    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">

    <log4j:configuration xmlns:log4j=
                "http://jakarta.apache.org/log4j/"
                        debug="false">

        <appender name="consoleAppender"
                class="org.apache.log4j.ConsoleAppender">
            <param name="Threshold" value="INFO" />
            <layout class="org.apache.log4j.PatternLayout">
                <param name="ConversionPattern" value="%d
                %-5p  [%c{1}] %m %n" />
            </layout>
        </appender>

        <logger name="javabeat.net.log4j" additivity="false" >
            <level value="INFO" />
            <appender-ref ref="consoleAppender"/>
        </logger>
    </log4j:configuration>

I keep getting this error from log4j:

SEVERE: log4j:ERROR A "org.apache.log4j.xml.DOMConfigurator" object is not assignable to a "org.apache.log4j.spi.Configurator" variable.

SEVERE: log4j:ERROR The class "org.apache.log4j.spi.Configurator" was loaded by

SEVERE: log4j:ERROR [WebappClassLoader (delegate=true; repositories=WEB-INF/classes/)] whereas object of type

SEVERE: log4j:ERROR "org.apache.log4j.xml.DOMConfigurator" was loaded by [WebappClassLoader (delegate=true; repositories=WEB-INF/classes/)].

SEVERE: log4j:ERROR Could not instantiate configurator [org.apache.log4j.xml.DOMConfigurator].

SEVERE: log4j:WARN No appenders could be found for logger (org.hibernate.type.BasicTypeRegistry).

SEVERE: log4j:WARN Please initialize the log4j system properly.

SEVERE: log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.

I'm out of ideas thx for the help

Upvotes: 5

Views: 4038

Answers (1)

Enrique San Mart&#237;n
Enrique San Mart&#237;n

Reputation: 2246

http://forum.spring.io/forum/spring-projects/batch/76295-log4j-classloader-problem

Hello, the problem that you mentioned it's almost always when you have a webapp that have the log4j.jar in they lib and also in the tomcat lib directory like it's explained in the link that i posted, so you have to choose, where is will be log4j, in all the webapps lib folders or only in the tomcat lib directory :)

UPDATE:

Also, you have to avoid to duplicate the commons-logging.jar in a tomcat lib and webapp lib directory.

regards

Upvotes: 0

Related Questions