Version 4

    Using your own log4j.xml file - class loader scoping


    Note: While you can solve this problem using class loader scoping, the preferred way to do this is using a RepositorySelector as shown here.  If you are already doing scoping then you might want to go ahead with this, but you should not need to use scoped class loading for log4j purposes alone.


    In order to use your own log4j.xml file you need to do something to initialize log4j in your application. If you use the default singleton initialization method where the first use of log4j triggers a search for the log4j initialization files, you need to configure ClassLoader to use scoped class loading, with overrides of the jboss classes. You also have to include the log4j.jar in your application so that new log4j singletons are created in your applications scope. The attached log4j.war example illustrates this. Its contents are:


    [starksm@banshee9100 deploy]$ zip -r ../ log4j.war
      adding: log4j.war/ (stored 0%)
      adding: log4j.war/META-INF/ (stored 0%)
      adding: log4j.war/META-INF/MANIFEST.MF (deflated 11%)
      adding: log4j.war/snoop.jsp (deflated 63%)
      adding: log4j.war/WEB-INF/ (stored 0%)
      adding: log4j.war/WEB-INF/classes/ (stored 0%)
      adding: log4j.war/WEB-INF/classes/log4j.xml (deflated 46%)
      adding: log4j.war/WEB-INF/jboss-web.xml (deflated 45%)
      adding: log4j.war/WEB-INF/lib/ (stored 0%)
      adding: log4j.war/WEB-INF/lib/log4j.jar (deflated 10%)
      adding: log4j.war/WEB-INF/web.xml (deflated 21%)


    The log4j.war/WEB-INF/jboss-web.xml is:

    <class-loading java2ClassLoadingCompliance="false">


    Note: that you cannot use a file using this approach, at least using log4j-1.2.8 because it preferentially searches for a log4j.xml resource and will find the conf/log4j.xml ahead of the application file. You could rename the conf/log4j.xml to something like conf/jboss-log4j.xml and then change the ConfigurationURL attribute of the Log4jService in the conf/jboss-service.xml to get around this.


    Referenced by: