1 2 Previous Next 19 Replies Latest reply on May 1, 2014 7:24 AM by malpanisiddhesh

    JBoss AS 7.1.3 logging

    ktfan

      I have an issue with the logging system in jboss AS 7.1.3. I am having my own logger class as below:

       

      My logger class

      import org.apache.commons.logging.LogFactory;

       

      public final class Logger

      {   

          private Class clazz;

          private transient org.apache.commons.logging.Log log;

       

       

          public static Logger getLogger(Class clazz) {      

              return new Logger(clazz);

          }

       

          protected Logger(Class clazz) {       

              this.clazz = clazz;

              this.log = LogFactory.getLog(clazz);

          }

       

       

          public void trace(Object o) {

              log.trace(o);

          }

       

       

          public void trace(Object o, Throwable throwable) {

              log.trace(o, throwable);

          }

       

       

          public void debug(Object o) {

              log.debug(o);

          }

       

       

          public void debug(Object o, Throwable throwable) {

              log.debug(o, throwable);

          }

       

       

          public void info(Object o) {

              log.info(o);

          }

       

       

          public void info(Object o, Throwable throwable) {

              log.info(o, throwable);

          }

       

       

          public void warn(Object o) {

              log.warn(o);

          }

       

       

          public void warn(Object o, Throwable throwable) {

              log.warn(o, throwable);

          }

       

      }

       

      My statement in other class which makes use of the logger

       

      Logger.getLogger(this.getClass()).warn("Unable to read the data from DB");

       

      My logging sub-system in standalone.xml

       

      <subsystem xmlns="urn:jboss:domain:logging:1.1">

                  <console-handler name="CONSOLE">

                      <level name="INFO"/>

                      <formatter>

                          <pattern-formatter pattern="%d{HH:mm:ss,SSS} %-5p [%c] (%t) %s%E%n"/>

                      </formatter>

                  </console-handler>

                  <periodic-rotating-file-handler name="FILE">

                      <formatter>

                          <pattern-formatter pattern="%d{HH:mm:ss,SSS} %-5p [%c] (%t) %s%E%n"/>

                      </formatter>

                      <file relative-to="jboss.server.log.dir" path="server.log"/>

                      <suffix value=".yyyy-MM-dd"/>

                      <append value="true"/>

                  </periodic-rotating-file-handler>

                  <logger category="com.arjuna">

                      <level name="WARN"/>

                  </logger>

                  <logger category="org.apache.tomcat.util.modeler">

                      <level name="WARN"/>

                  </logger>

                  <logger category="sun.rmi">

                      <level name="WARN"/>

                  </logger>

                  <logger category="jacorb">

                      <level name="WARN"/>

                  </logger>

                  <logger category="jacorb.config">

                      <level name="ERROR"/>

                  </logger>

                  <root-logger>

                      <level name="INFO"/>

                      <handlers>

                          <handler name="CONSOLE"/>

                          <handler name="FILE"/>

                      </handlers>

                  </root-logger>

              </subsystem>

       

       

      The logged message does not appear in the server.log but a system.out.println message does appear. This issue was not happening in AS 7.1.1.

       

      Is there any tweak I can make in AS 7.1.3 ?


        • 1. Re: JBoss AS 7.1.3 logging
          jamezp

          Do you have a logging configuration in your deployment by chance? It would have to be a log4j.xml, log4j.properties, logging.properties, jboss-logging.properties or jboss-log4j.xml.

           

          --

          James R. Perkins

          • 2. Re: JBoss AS 7.1.3 logging
            ktfan

            There is a default logging.properties under the standalone/configuration directory, but I don't change any lines there.

            • 3. Re: JBoss AS 7.1.3 logging
              jamezp

              Okay, no problem. That should be there. I'm not too sure why it wouldn't be showing up. Do you include commons-logging with your deployment? The server does add a dependency by default to commons-logging for all deployments.

               

              --

              James R. Perkins

              • 4. Re: JBoss AS 7.1.3 logging
                ktfan

                James,

                 

                    I have these dependencies :

                 

                  

                   <dependency>

                                                        <groupId>org.slf4j</groupId>

                                                        <artifactId>slf4j-api</artifactId>

                                                        <version>${sl4fj-api.version}</version>

                                              </dependency>

                 

                 

                                              <dependency>

                                                        <groupId>org.slf4j</groupId>

                                                        <artifactId>slf4j-log4j12</artifactId>

                                                        <version>${slf4j-log4j12.version}</version>

                                              </dependency>

                 

                 

                <dependency>

                                              <groupId>commons-logging</groupId>

                                              <artifactId>commons-logging</artifactId>

                                              <version>1.1.1</version>

                </dependency>

                 

                <dependency>

                                                        <groupId>org.jboss.logging</groupId>

                                                        <artifactId>jboss-logging</artifactId>

                                                        <version>3.1.2.GA</version>

                </dependency>

                 

                 

                <dependency>

                                              <groupId>commons-logging</groupId>

                                              <artifactId>commons-logging</artifactId>

                                              <version>1.1.1</version>

                </dependency>

                 

                 

                Is there any conflict ?

                • 5. Re: JBoss AS 7.1.3 logging
                  jamezp

                  There could be for sure. Those are all provided by the server. Try marking them all as <scope>provided</scope> and see if that works.

                   

                  --

                  James R. Perkins

                  • 6. Re: JBoss AS 7.1.3 logging
                    ktfan

                    I just tried with the provided scope, the problem still persists. Is there any way to bypass jboss native logging system ?

                    • 7. Re: JBoss AS 7.1.3 logging
                      jamezp

                      Taking a second look at the dependencies is there a reason to have all those logging dependencies? It looks like you're, in a sense, creating your own logging facade.

                       

                      There is a way to bypass the logging subsystem, but doing so doesn't allow for runtime changes to the logging configuration. For example you can't turn on debug logging without a restart.

                       

                      --

                      James R. Perkins

                      • 8. Re: JBoss AS 7.1.3 logging
                        ktfan

                        In fact I am not sure how can I implement the jboss logging subsystem. Do I need to have my own logging wrapper class ? Or is there any sample I can refer to ?

                        • 9. Re: JBoss AS 7.1.3 logging
                          jamezp

                          No there is nothing you need to implement. Any logging framework should work fine.

                           

                          I did create test the logger wrapper you pasted above in a test and it worked for me. I saw the output on the console. Try turning on trace logging for org.jboss.as.logging to see if it gives you any more information.

                           

                          CLI to turn on trace:

                          /subsystem=logging/org.jboss.as.logging:add(level=TRACE)
                          
                          /subsystem=logging/console-handler=CONSOLE:write-attribute(name=level,value=TRACE)
                          

                           

                           

                          That will turn on trace logging for the logging subsystem and the console handler.

                           

                          --

                          James R. Perkins

                          • 10. Re: JBoss AS 7.1.3 logging
                            ktfan

                            I did the following steps, and now I can see my logging messages in different log files as defined in the standalone-full.xml

                             

                            1) Add the line under standalone.conf

                            JAVA_OPTS="$JAVA_OPTS -Dorg.jboss.as.logging.per-deployment=false"

                            2) Remove all the logging dependencies in all maven POM files

                            3) Only logging dependency is log4j with <scope>provided</scope>

                             

                            Thanks James for the feedbacks provided so far.

                            • 11. Re: JBoss AS 7.1.3 logging
                              jamezp

                              The clue there might be the org.jboss.as.logging.per-deployment property. It sounds like you might have a logging configuration file, log4j or logging.properties, somewhere in your deployment.

                               

                              --

                              James R. Perkins

                              • 12. Re: JBoss AS 7.1.3 logging
                                anjs28

                                Hi,

                                 

                                I am currently working on creating my own logging system on jboss-as-7.1.1.Final. Can you show me how you have configured dependencies in module.xml?

                                 

                                Thanks in advance,

                                Anjs

                                • 13. Re: JBoss AS 7.1.3 logging
                                  ktfan

                                  Hi Anjs:

                                   

                                     I did not really configure the dependencies in module.xml as far as the logging system concerned.

                                  • 14. Re: JBoss AS 7.1.3 logging
                                    veeramarni84

                                    FYI, if you have openjpa module and your jboss is using it then you probably end with no logging when using slf4j as the openjpa uses slf4j module. I am not sure what is issue causing no logging when using jboss's slf4j module. But when i exclude using openjpa module, i am able to log.

                                     

                                    <jboss-deployment-structure>

                                              <deployment>

                                                        <!-- Exclusions allow you to prevent the server from automatically adding

                                                                  some dependencies -->

                                                        <exclusions>

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

                                                                  <module name="org.slf4j" />

                                                                  <module name="org.slf4j.ext" />

                                                                  <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.jcl-over-slf4j" />

                                                                  <module name="org.slf4j.impl" />

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

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

                                                        </exclusions>

                                              </deployment>

                                    </jboss-deployment-structure>

                                    1 2 Previous Next