Version 4

    Using your own file - class loader scoping

    To use a file, you have to make the change in conf/jboss-service.xml as shown below. This is necessary for the reasons mentioned above. Essentially you are changing the log4j resource file that jBossAS will look for. After making the change in jboss-service.xml make sure you rename the conf/log4j.xml to the name that you have give in jboss-service.xml (in this case jboss-log4j.xml).

    <!-- ==================================================================== -->
    <!-- Log4j Initialization                                                 -->
    <!-- ==================================================================== -->
    <mbean code="org.jboss.logging.Log4jService"
     <attribute name="ConfigurationURL">resource:jboss-log4j.xml</attribute>
     <!-- Set the org.apache.log4j.helpers.LogLog.setQuiteMode. As of log4j1.2.8
     this needs to be set to avoid a possible deadlock on exception at the
     appender level. See bug#696819.
     <attribute name="Log4jQuietMode">true</attribute>
     <!-- How frequently in seconds the ConfigurationURL is checked for changes -->
     <attribute name="RefreshPeriod">60</attribute>

    Drop log4j.jar in your myapp.war/WEB-INF. Make the change in jboss-web.xml for class-loading, as shown in the section above. In this case, myapp.war/WEB-INF/jboss-web.xml looks like this:

     <class-loading java2ClassLoadingCompliance="false">

    Now, in your deploy/myapp.war/WEB-INF/classes create a Sample

    # Debug log4j
    log4j.rootLogger=debug, myapp
    log4j.appender.myapp.layout.Title='All' Log

    The above property file sets the log4j debug system to true, which displays log4j messages in your jboss log. You can use this to discover errors, if any in your properties file. It then produces a nice HTML log file and places it in your application's WEB-INF/logs directory. In your application, you can call this logger with the syntax:

    private static Logger log = Logger.getLogger("myapp");
    log.debug("############## A debug message from myapp logger #########");

    If all goes well, you should see this message in myapp.html. For more information about loggers, appenders and layouts, visit the log4j website.


    After jBossAS has reloaded conf/jboss-service.xml (you may have to restart jBossAS), touch myapp.war/WEB-INF/web.xml so that jboss reloads the config for your application. As the application loads you should see log4j debug messages showing that its reading your And voila, you have your own logging system, independent of the jBoss logging system.


    Referenced by: