14 Replies Latest reply on Nov 14, 2012 6:15 PM by Micky Mick

    JBOSS logging

    Micky Mick Newbie

      Hello -

       

      I am a WAS admin and new to jboss. I need to configure JBoss 6 to support Java Logging API from the application code.

      How to configure jboss for logging (Application code independent of any actual implementation). i have checked documentation but it is not very clear.

      Can someone please help or point me in the right direction?

       

      I am using JBOSS EAP 6 on Linux.

       

      Thanks in advance,

      AdminMich


        • 1. Re: JBOSS logging
          Stephen Coy Master

          Hi there,

           

          Welcome to JBoss!

           

          Depending upon what you mean by "Application code independent of any actual implementation", you may not need to do anything at all.

           

          You can control what gets logged from the admin console or use the CLI.

          • 2. Re: JBOSS logging
            Micky Mick Newbie

            How do i enable standard Java Logging on jboss ? For example, if there is an issue in app and we need to enable trace for troubleshooting.

            In WebSphere this option is already implemented in console where you can enable diagnostic trace on the fly. Is there something similar in jboss?

             

            Do you know of any articles on jboss logging and examples other than the documentation?


             

            Thank you,

            AdminMich

            • 4. Re: JBOSS logging
              Micky Mick Newbie

              Thanks for your reply, Yes i have checked it out but i am confused on how to enable logging for a specific class for an application. I see that there is a custom handler but i am not sure how to configure it. Is there any info about that?

              I need to be able to enable logs for specific app classes (for example com.classname*=all=enabled)

              • 5. Re: JBOSS logging
                Stephen Coy Master

                You don't need to worry about handlers for now.

                 

                Just click the "Add" button in the console as shown in the picture, enter "com.classname" and set the desired logging level.

                 

                jboss7-logging.png

                • 6. Re: JBOSS logging
                  Stephen Coy Master

                  You can also use the CLI interface to do the same thing:

                   

                  {code:bash}bin/jboss-cli.sh --connect "/subsystem=logging/logger=com.classname:add(level=DEBUG)"{code}

                  • 7. Re: JBOSS logging
                    Micky Mick Newbie

                    Thanks, does this require a restart? Can it be applied in runtime? Also if you have multiple classes you have to add each and every class manually?

                     

                    Cheers,

                    AdminMich

                    • 8. Re: JBOSS logging
                      James Perkins Master

                      It can be applied at runtime. Nearly all the logging configuration changes do not require a restart.

                       

                      --

                      James R. Perkins

                      • 9. Re: JBOSS logging
                        Stephen Coy Master

                        Michel G wrote:

                         

                        ... Also if you have multiple classes you have to add each and every class manually?

                         

                        Normally, just the package name is used. This encompasses all classes in the package as well as subpackages:

                         

                        {code:bash}bin/jboss-cli.sh --connect "/subsystem=logging/logger=com.package.name:add(level=DEBUG)"{code}

                        • 10. Re: JBOSS logging
                          Micky Mick Newbie

                          Thanks i see the app logging under server.log, i want to have a separate file for the application logs. i have configured a new Size Rotating File Handler (along with pointing the class to use it) and i can see the new app.log file but it is empty and the logging is still going to server.log.

                           

                          Any ideas?

                           

                          Cheers

                          • 11. Re: JBOSS logging
                            James Perkins Master

                            You need to create a logger (category) and assign the handler to it.

                             

                                    <subsystem xmlns="urn:jboss:domain:logging:1.0">
                                        ...
                                        <size-rotating-file-handler name="myapp-handler" auto-flush="true">
                                            <level name="INFO"/>
                                            <formatter>
                                                <pattern-formatter pattern="%d{HH:mm:ss,SSS} %-5p [%c] (%t) %s%E%n"/>
                                            </formatter>
                                            <append value="true"/>
                                            <file relative-to="jboss.server.log.dir" path="myapp.log"/>
                                            <max-backup-index value="10"/>
                                            <rotate-size value="100m"/>
                                        </size-rotating-file-handler>
                            
                            
                                        <logger category="com.myapp" use-parent-handler="false">
                                            <handlers>
                                                <handler name="myapp-handler"/>
                                            </handlers>
                                        </logger>
                                        ...
                                    </subsystem>
                            
                            

                             

                            If you want your messages to also go to the server.log just remove the use-parent-handler attribute or set it to true.

                             

                            --

                            James R. Perkins

                            • 12. Re: JBOSS logging
                              Micky Mick Newbie

                              Yes my configuration is alomst the same, i have defined the logger and i even restarted all jboss instance but it still doesnt print in app.log. When i changed use-parent-handler='false' from true it stopped printing in server.log but app.log is still empty. Am i missing something in configuration below?

                               

                               

                                      <subsystem xmlns="urn:jboss:domain:logging:1.0">
                                          ...
                                          <size-rotating-file-handler name="
                              Logssizebased" auto-flush="false">
                                              <level name="INFO"/>
                                              <file relative-to="jboss.server.log.dir" path="app.log"/>
                                          </size-rotating-file-handler>


                                          <logger category="
                              org.apache.jsp.test" use-parent-handler="false">

                                              <level name="WARNING"/>
                                              <handlers>
                                                  <handler name="
                              Logssizebased"/>
                                              </handlers>
                                          </logger>
                                          ...
                                      </subsystem>


                               

                               

                              PS: i have configured it thru management console, not sure if it makes a difference

                              • 13. Re: JBOSS logging
                                James Perkins Master

                                I would set the auto-flush to true, but other than that it looks okay. Are all the loggers in your application using something like Logger.getLogger("org.apache.jsp.test")? Also are you printing error and warning messages? The way you have the logger setup is it will only print WARNING or higher messages.

                                 

                                Nope, I would suggest configuring through the management console instead of updating the XML by hand

                                 

                                --

                                James R. Perkins

                                1 of 1 people found this helpful
                                • 14. Re: JBOSS logging
                                  Micky Mick Newbie

                                  Thanks it works when i set auto-flush to true.

                                  For some reason auto-flush must be set to true or else it will not work. Does this happen in your environment too?