Use my own log4j.xml with EAP 6.1

Latest response

Seems that this question is everywhere, but I've yet to come up with a solution. I have a WEB-INF\classes\log4j.xml with the root level of the logger set to DEBUG.

I'm deploying the following in my WEB-INF\lib directory
log4j-1.2.17.jar
slf4j-api-1.7.5.jar
slf4j-log4j12-1.7.5.jar

I have a jboss-deployment-structure.xml file at the root of WEB-INF\ that looks like this.


<?xml version="1.0" encoding="UTF-8"?> <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 in my run.conf there was already a line for
JAVA_OPTS="$JAVA_OPTS -Dorg.jboss.as.logging.per-deployment=false"

and I've confirmed this is getting used from the console.log.

When JBOSS starts up all I get is INFO messages and it doesn't appear to be using my log4j.xml configuration whatsoever.

What are the steps needed to use my log4j.xml and my deployed jars for logging?

Responses

I basically have done what it says in the link below, but it doesn't seem to work for me. Is there somewhere I can confirm how the logging is getting initialized? Is there some other log file that might have this information?

https://access.redhat.com/site/solutions/105653

Hi Dale. Sorry you haven't seen a response to this yet. Let me see if I can track down some help for you.

Hi,

The document you referenced should be working for you. Can I suggest that you raise a support case and attach your war so that we can have a closer look?

One note though, with this property, -Dorg.jboss.as.logging.per-deployment=false, JBoss won't automatically search your deployment for a config file. You must configure the logger in your code and use your config file.

Regards
Dave

Thanks for the response. Can you confirm where the jboss-deployment-structure.xml file should go? Root of WEB-INF or root of WEB-INF/classes?

When you say configure the logger in the code, what exactly are you referring to. I don't have to do anything specifically for Tomcat and the logging just works.

This is a typical logger initialization which I don't tell it to use my config file, it just picks up the log4j.xml that's in the classpath. Why won't JBoss do that as well with -Dorg.jboss.as.logging.per-deployment=false property set.

private static IntegrationLogger logger = IntegrationLogger.getLogger( SubscriptionController.class );

.....

// At some point in a function 
logger.debug( "Removing the event: " + deferredResult );

These debug messages never show up.

For the Module Exclusions in jboss

<module name="org.apache.log4j" />

is this supposed to be where the Logger.class is found? What if we use slf4j? Should this be

<module name="org.slf4j" />  

Or do I need both of them defined and what would that look like?

Here's what the Integration Logger looks like that's referenced above.

package com.somename.integration.util;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public final class IntegrationLogger
{
    private Logger logger = null;

    private IntegrationLogger()
    {
    }

    public static IntegrationLogger getLogger( String clazz )
    {
        IntegrationLogger logger = new IntegrationLogger();
        logger.logger = LoggerFactory.getLogger( clazz );
        return logger;
    }

    public static IntegrationLogger getLogger( Class<?> clazz )
    {
        return getLogger( clazz.getName() );
    }

    public void info( String message )
    {
        logger.info( message );
    }

    public void debug( String message )
    {
        logger.debug( message );
    }

    public void warn( String message )
    {
        logger.warn( message );
    }

    public void error( String message )
    {
        logger.error( message );
    }
}

By adding the org.slf4j to the exclusions, that seemed to work. The file is now like this.

<?xml version="1.0" encoding="UTF-8"?>
<jboss-deployment-structure>
    <deployment>
        <!-- Exclusions allow you to prevent the server from automatically adding some dependencies -->
        <exclusions>
            <module name="org.apache.log4j" />
            <module name="org.slf4j" />
        </exclusions>
    </deployment>
</jboss-deployment-structure>

Do I need both or should I just have the org.slf4j?

The odd behavior that I see now is that the DEBUG messages are wrapped in an INFO message.

2013-09-12 08:07:43,712 INFO  [stdout] (http-/10.226.76.12:8080-3) 2013-09-12 08:07:43,711 [http-/10.226.76.12:8080-3] DEBUG: com.dstsystems.integration.controller.SubscriptionController - Removing the event: org.springframework.web.context.request.async.DeferredResult@1c8f277

NOTE: This only worked when I put the jboss-deployment-structure.xml in the root of the WEB-INF\ and I have removed it from WEB-INF\classes.

Yes, the jboss-deployment-structure.xml goes in the WEB-INF directory[1].

You would need both module exclusions if you wanted to exclude the jars supplied by the application server and use those you have packaged.

[1] https://access.redhat.com/site/documentation/en-US/JBoss_Enterprise_Application_Platform/6.1/html-single/Development_Guide/index.html#Add_an_Explicit_Module_Dependency_to_a_Deployment1