1 Reply Latest reply on Aug 25, 2016 12:39 PM by James Perkins

    Logging based on class name in JBoss 7.0.0

    Anand Kadhi Newbie

      Hi,

      I am using Java 1.7 along with JBoss 7.0.0 version with standalone.xml having logging version <subsystem xmlns="urn:jboss:domain:logging:1.0"> . I have a requirement to separate logs based on class name i.e for a particular class the log file should be separate.

       

      Java  Class ::

              package com.task;

       

              public class MyService {

              /**

               * Logger.

               */

              private static final Logger LOGGER = Logger.getLogger(MyService.class);

       

      Then all the logs should be redirected to a file registered against this class name in JBoss `standalone.xml` file , for instance i have done like

      standalone.xml

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

                  <console-handler name="CONSOLE" autoflush="true">

                      <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" autoflush="true">

                      <level name="INFO"/>

                      <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"/>

                  </periodic-rotating-file-handler>

                 

                  <periodic-rotating-file-handler name="MY_LOG" autoflush="true">

                      <level name="DEBUG"/>

                      <formatter>

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

                      </formatter>

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

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

                  </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="com.task.MyService">

                      <level name="DEBUG"/>

                      <handlers>

                          <handler name="MY_LOG"/>

                      </handlers>

                  </logger>

                  <root-logger>

                      <level name="INFO"/>

                      <handlers>

                          <handler name="CONSOLE"/>

                          <handler name="FILE"/>                   

                      </handlers>

                  </root-logger>

              </subsystem>

       

      The log file with name **my_log.log** is getting created but the logs are not redirected to that file they are still written over the **server.log** file by default.

       

      How can i log the statements from this **MyService.class** to write into **my_log.log**  file only ?

       

      Also if i insert the <handler name="MY_LOG"/> into Root-Logger and use "use-parent-handler = false" then on restart of the application the standalone.xml gets overwritten and the "use-parent-handler = false" is removed automatically. How can i stop this overwriting behavior please suggest.

        • 1. Re: Logging based on class name in JBoss 7.0.0
          James Perkins Master

          The configuration looks mostly correct to me. You might want to add use-parent-handlers="false" tot he logger so they're not written to the console or the server.log. If you're editing the XML while the server is running there is a good chance it will get overwritten. Also changes to the XML while the server is running are not recognized until the server is restarted. Using the web console or CLI to configure the server is the suggested approach.

           

          --

          James R. Perkins