Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using log4j with JBoss 7.1

Tags:

log4j

jboss7.x

How can I use log4j with JBoss 7.1?

I have a log4j-1.2.16.jar in my WebContent/WEB-INF/lib folder. When I output the result of Logger.getRootLogger().getClass().toString() I get class org.jboss.logmanager.log4j.BridgeLogger which is wrong.

If I add Dependencies: org.apache.commons.logging to my MANIFEST.MF file I get the same result.

This results into the problem that my log4j.properties file (which I created unter WEB-INF/classes) is ignored.

like image 667
T3rm1 Avatar asked Mar 06 '12 13:03

T3rm1


People also ask

Does JBoss use Log4j?

JBoss AS uses log4j as logging framework.

What is Apache Log4j use for?

Apache Log4j is a Java-based logging utility. Log4j Java library's role is to log information that helps applications run smoothly, determine what's happening, and help with the debugging process when errors occur. Logging libraries typically write down messages to the log file or a database.


1 Answers

There will soon be a way that will just work for you, but currently you have to exclude the log4j dependency from your deployment. You will also have to manually invoke the PropertyConfigurator.configure() to load the properties file.

The following file (jboss-deployment-structure.xml) needs to contain the following:

<jboss-deployment-structure>
    <deployment>
        <!-- Exclusions allow you to prevent the server from automatically adding some dependencies -->
        <exclusions>
            <module name="org.apache.log4j" />
        </exclusions>
    </deployment>
</jboss-deployment-structure>

Then adding including your own version of log4j in the WEB-INF/lib directory should work as you expect it to.

like image 138
James R. Perkins Avatar answered Sep 24 '22 00:09

James R. Perkins