3

I don't want to configure the logging using the standalone.xml or CLI, because it requires additional steps for my colleagues to get a working development environment. I want to have these configuration files checked in with our source code and automatically applied at deployment time.

With JBoss 5 there was the possibility to declare logging in the jboss-log4j.xml. Is there an equivalent to this file in JBoss 7, too?

We want to use slf4j and logback.

s.froehlich
  • 863
  • 1
  • 11
  • 19
  • 1
    try this hope this may help you http://stackoverflow.com/questions/14182257/using-applications-log4j-configuration-under-jboss-7-1-1/14337990#14337990 – gYanI Feb 15 '13 at 13:38

2 Answers2

6

If you want to use your own logging and not the JBoss logging, you need to do a couple steps, per application that you want on your own logging:

Exclude JBoss logging

Write a jboss-deployment-structure.xml file to exclude the jboss log4j or slf4j or any other logging modules that are included in JBoss.

Example for a WAR...place in WAR/WEB-INF/

<jboss-deployment-structure>
    <deployment>
        <exclusions>
            <module name="org.slf4j"/>
        </exclusions>
    </deployment>
</jboss-deployment-structure>

Include your own jars

Simply place your own jars in your lib folder

For a WAR, place in WAR/WEB-INF/lib

Include your logging config

Simply include your own config files like normal

For a WAR, place in WAR/WEB-INF/classes

Start JBoss with a -D flag

Run your server using:

$ ./standalone.sh -Dorg.jboss.as.logging.per-deployment=false

Example for an EAR

Place jboss-deployment-structure.xml in EAR/META-INF

<jboss-deployment-structure>
    <sub-deployment name="myWar.war>
        <exclusions>
            <module name="org.slf4j"/>
        </exclusions>
    </sub-deployment>
    <sub-deployment name="myWar2.war>
        <exclusions>
            <module name="org.slf4j"/>
        </exclusions>
    </sub-deployment>
    <sub-deployment name="myEjb.jar>
        <exclusions>
            <module name="org.slf4j"/>
        </exclusions>
    </sub-deployment>
</jboss-deployment-structure>

In EAR/lib, include your JARS

In each deployment, add the configuration/properties for that deployment

Start the server: $./standalone.sh -Dorg.jboss.as.logging.per-deployment=false

This should have swapped out the JBoss version of the JARs with your own, therefor allowing your own JARs and config files to get picked up. Let me know if you have any questions.

Jean-Charles
  • 1,690
  • 17
  • 28
jyore
  • 4,715
  • 2
  • 21
  • 26
3

You can add a logback configuration to your application. You would need to include logback in your application. You might have to use a jboss-deployment-structure.xml, similar to the log4j exclusion one, to exclude the org.slf4j module. This will only configure logging for your application though.

If you're concern is just getting the logging subsystem configured there are a couple other possibilities that could work depending on your environment.

The first and one that would work with any environment is create a CLI script that could be checked in and run.

${JBOSS_HOME}/bin/jboss-cli.sh --connect --file path/to/script.cli

If you're using maven the second possibility would be to use the maven plugin. You can execute CLI commands with the plugin. Just add the execute-commands goal to run before the deploy goal runs.

James R. Perkins
  • 16,800
  • 44
  • 60
  • I'll accept this as the answer for my question because it's the most straight forward way to configure the JBoss logging in a general way. – s.froehlich Feb 17 '13 at 16:49