3 Replies Latest reply on Jun 16, 2014 1:26 PM by jamezp

    JBoss EAP 6.2 - setting up proper application logging (issues)

    masterm1nd

      Hello all,

       

      currently i'm trying to properly setup "per application" logging using slf4j with log4j as underlying implementation. As stated application server in use is EAP 6.2 - we're using war projects with

      frameworks like JSF 1.2 or 2.1, JPA/Hibernate (server dependencies .. so in maven these are configured as provided)

       

      i tried the following but unfortunately nothing worked as expected:

       

      1st approach)

       

      custom log4j.properties located under /some/dir

       

      jboss deployment structure with following exclusions:

       

      <exclusions>

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

          <module name="org.apache.commons.logging" />

          <module name="org.jboss.logging" />

          <module name="org.jboss.logging.jul-to-slf4j-stub" />

          <module name="org.jboss.logmanager" />

          <module name="org.jboss.logmanager.log4j" />

          <module name="org.slf4j" />      

      </exclusions>

       

      following dependencies referenced via maven:

       

      <dependency>

          <groupId>org.slf4j</groupId>

          <artifactId>slf4j-api</artifactId>

          <version>1.7.7</version>

      </dependency>          

      <dependency>

          <groupId>org.slf4j</groupId>

          <artifactId>slf4j-log4j12</artifactId>

          <version>1.7.7</version>

      </dependency>

      <dependency>

          <groupId>com.slf4j</groupId>

          <artifactId>jcl-over-slf4j</artifactId>

          <version>1.7.7</version>

      </dependency>                                                  

      <dependency>

          <groupId>log4j</groupId>

          <artifactId>log4j</artifactId>

          <version>1.2.17</version>

      </dependency>

      (jul-to-slf4j dependency did nothing, tried with and without)

       

      calling log4j property configurator in the application like this:

      PropertyConfigurator.configure("/path/to/log4j.properties");

       

      Result: logging does work for the application itself. but jsf / el / hibernate output is not written to my log file, neither am i able to receive errors of those frameworks via our log4j mailappender

      (also tried setting according log4j properties like: log4j.logger.javax.faces=INFO ... ) ..

       

      2nd approach)

       

      set -Dorg.jboss.as.logging.per-deployment=true

      put log4j.properties to the classpath (src/main/java)

       

      following dependencies referenced via maven:

      <dependency>

          <groupId>org.slf4j</groupId>

          <artifactId>slf4j-api</artifactId>

          <version>1.7.7</version>

      </dependency>

       

      nothing excluded via jboss-deployment-structure


      Result: does not work ... log4j.properties doesn't seem to be picked up


      3rd approach)


      set -Dorg.jboss.as.logging.per-deployment=true

      put logging.properties to the classpath (src/main/java)

       

      following dependencies referenced via maven:

      <dependency>

          <groupId>org.slf4j</groupId>

          <artifactId>slf4j-api</artifactId>

          <version>1.7.7</version>

      </dependency>

       

      Result: WORKING ... everything is picked up as expected and logged to the according file...nevertheless this approach is not feasible for us because we use log4j in all of our projects and logging.properties does not allow to specify a mail appender


       

      What am i doing wrong? Maybe someone could point out things i missed or configured the wrong way.


      Thanks!

        • 1. Re: JBoss EAP 6.2 - setting up proper application logging (issues)
          jamezp

          Because JSF, EL and Hibernate are server modules they will always use the servers logging configuration. You can't use per-deployment logging to change the configuration for server modules.

           

          With JBoss EAP you can however use a log4j appender as a custom-handler. Here's an example of adding a org.apache.log4j.FileAppender via CLI:

          /subsystem=logging/custom-handler=fa:add(class=org.apache.log4j.FileAppender,module=org.apache.log4j,properties={"append"="true","immediateFlush"="true","file"="${jboss.server.log.dir}/fa.log"})
          

           

          --

          James R. Perkins

          • 2. Re: JBoss EAP 6.2 - setting up proper application logging (issues)
            masterm1nd

            Hi,

             

            thanks for answering.

             

            But can you tell me why 3rd approach) has been working properly?

            Because with this configuration everything (logging of my application and server modules like hibernate, jsf) have been written to the same log file....(the one i specified in logging.properties)

             

            Only thing i am missing with this approach is the mail appender...

            • 3. Re: JBoss EAP 6.2 - setting up proper application logging (issues)
              jamezp

              To be honest it shouldn't be working like that at all. If the logging.properties configuration is being used then the server modules should not be using the same log context. If this is happening, it's a bug and you shouldn't rely on the behavior.

               

              As to the mail appender you could always write one extending either a java.util.logging.Handler or org.jboss.logmanager.ExtLogHandler.

               

              --

              James R. Perkins