6 Replies Latest reply on Oct 2, 2012 3:25 AM by Grega Krajnc

    Logging with JBoss AS 7.1.1

    Grega Krajnc Newbie

      Hello, every body!

       

      I searched around, but I haven't found answer on my problem. I want to log something in the way like this:

       

      {code}

      private static final Logger logger = Logger.getLogger(MyClass.class.getName());

       

      public void someMethod() {

          MyClass.logger.entering("MyClass", "someMethod", new String[]{"param1", "param2"});

      }

      {code}

      In log file i find string like this:

       

      {font:courier new}

      20:11:43,211 FINER [my.MyClass] (http-localhost-127.0.0.1-8080-1) ENTRY param1 param2

      {font}

      Why I don't see print of "MyClass" and "someMethod"? Identical code works fine in IBM WebSphere 8.

        • 1. Re: Logging with JBoss AS 7.1.1
          Tomaz Cerar Master

          Hi,

           

          What are you using? JUL?

           

          How does your logging configuration looks like? (logging subsystem in standalone.xml)

           

          --

          tomaz

          • 2. Re: Logging with JBoss AS 7.1.1
            Grega Krajnc Newbie

            This is my subsystem configuration for logging.

             

            If JUL means java.util.logging - yes, I use that one.

             

            {code:xml}

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

                        <console-handler name="CONSOLE">

                            <level name="ALL"/>

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

                        <logger category="org.jboss.security.authentication.JBossCachedAuthenticationManager" use-parent-handlers="true">

                            <level name="OFF"/>

                        </logger>

                        <logger category="my.package" use-parent-handlers="true">

                            <level name="ALL"/>

                        </logger>

                        <root-logger>

                            <level name="INFO"/>

                            <handlers>

                                <handler name="CONSOLE"/>

                                <handler name="FILE"/>

                            </handlers>

                        </root-logger>

                    </subsystem>

            {code}

            • 3. Re: Logging with JBoss AS 7.1.1
              James Perkins Master

              You just need to change your pattern. You just need to add a %C for the class name and a %M for the method name.

               

              You're pattern should probably looks something like:

               

              %d{HH:mm:ss,SSS} %-5p %C.%M [%c] (%t) %s%E%n
              

               

              You can remove the %c if you don't want the logger name.

               

              --

              James R. Perkins

              1 of 1 people found this helpful
              • 4. Re: Logging with JBoss AS 7.1.1
                Grega Krajnc Newbie

                Thank you for your suggestion, but this pattern does not resolve my problem correctly. %C and %M works though caller location information, which is slow as well. I expect, that output in log would be exact string I put in eg. "entering()" method.

                • 5. Re: Logging with JBoss AS 7.1.1
                  James Perkins Master

                  If you specify the source name or the method name then no caller information is calculated. It's taken directly from what you entered for both values.

                   

                  You could specify a static entry logger so you can define a custom format and not have to worry about the caller location information overhead for non-entry logs.

                   

                   

                  <subsystem xmlns="urn:jboss:domain:logging:1.1">
                      <console-handler name="CONSOLE">
                          <level name="ALL"/>
                          <formatter>
                              <pattern-formatter pattern="%d{HH:mm:ss,SSS} %-5p [%c] (%t) %s%E%n"/>
                          </formatter>
                      </console-handler>
                      <console-handler name="ENTRY_CONSOLE">
                          <level name="ALL"/>
                          <formatter>
                              <pattern-formatter pattern="%d{HH:mm:ss,SSS} %-5p %C.%M [%c] (%t) %s%E%n"/>
                          </formatter>
                      </console>
                  
                  
                      <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>
                  
                  
                      <periodic-rotating-file-handler name="ENTRY_FILE">
                          <formatter>
                              <pattern-formatter pattern="%d{HH:mm:ss,SSS} %-5p %C.%M [%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>
                      <logger category="org.jboss.security.authentication.JBossCachedAuthenticationManager" use-parent-handlers="true">
                          <level name="OFF"/>
                      </logger>
                      <logger category="my.package" use-parent-handlers="true">
                          <level name="ALL"/>
                      </logger>
                      <logger category="my.package.entry" use-parent-handlers="false">
                          <level name="ALL"/>
                          <handlers>
                              <handler name="ENTRY_CONSOLE"/>
                              <handler name="ENTRY_FILE"/>
                          </handlers>
                      </logger>
                      <root-logger>
                          <level name="INFO"/>
                          <handlers>
                              <handler name="CONSOLE"/>
                              <handler name="FILE"/>
                          </handlers>
                      </root-logger>
                  </subsystem>
                  
                  

                   

                   

                  public static final Logger logger = Logger.getLogger("my.package.entry");
                  
                  
                  public void someMethod() {
                      MyClass.logger.entering("MyClass", "someMethod", new String[]{"param1", "param2"});
                  }
                  
                  

                   

                  This is probably not ideal, but it should work.

                   

                  --

                  James R. Perkins

                  • 6. Re: Logging with JBoss AS 7.1.1
                    Grega Krajnc Newbie

                    Thank you very much for this tip. It worked for me.