1 2 3 Previous Next 35 Replies Latest reply on Feb 19, 2013 4:48 AM by Rohan Emmanuel

    JBoss 7 Logging

    Joseph Fouts Novice

      Using JBoss 7 logging how would I accomplish the following?

       

      produce 2 unique log files.  Log1/Log2

      these files canl reside in the same folder as jboss server.log.

      have each file roll daily with a date.

       

      The log files will only contain log entries from my application. (no jboss entries)

      package for main application is "com.myApp".

       

      Log1 will contain all messages from my application. (Fatal/Error/Warn/Info/Debug/Trace)

       

      Log2 will contain only the following messages from my application. (Fatal/Error/Warn)

       

      ----------------------------------------------------------------------------------------------------------------------------------

       

      Do I need to define something in standalone.xml?

        

      Or does something like this require a custom logger?

       

       

      Any help is greatly appreciated.

       

      Thanks.

        • 1. Re: JBoss 7 Logging
          James Perkins Master

          Joseph,

          No custom logger is needed in this case at all. It sounds like what you want to use is a periodic-rotating-file-handler. The easiest way to configure this would be through one of the management consoles.

           

          In the CLI console you would do the following.

           

          Create the first handler:

          /subsystem=logging/periodic-rotating-file-handler=log1:add(file={"relative-to"=>"jboss.server.log.dir","path"=>"log1.log"},suffix=".yyyy-MM-dd",level=ALL,append=true,autoflush=true)
          

           

          Create the second handler:

          /subsystem=logging/periodic-rotating-file-handler=log2:add(file={"relative-to"=>"jboss.server.log.dir","path"=>"log2.log"},suffix=".yyyy-MM-dd",level=WARN,append=true,autoflush=true)
          

           

           

          Create a logger and attach the handlers:

          /subsystem=logging/logger=com.myApp:add(level=ALL,handlers=["log1","log2"])
          

           

          You could also use the web console to achieve the same results.

           

          The XML in would look something like this:

           

          <subsystem xmlns="urn:jboss:domain:logging:1.1">
              ...
                      <periodic-rotating-file-handler name="log1" autoflush="true">
                          <level name="ALL"/>
                          <file relative-to="jboss.server.log.dir" path="log1.log"/>
                          <suffix value=".yyyy-MM-dd"/>
                          <append value="true"/>
                      </periodic-rotating-file-handler>
                      <periodic-rotating-file-handler name="log2" autoflush="true">
                          <level name="WARN"/>
                          <file relative-to="jboss.server.log.dir" path="log2.log"/>
                          <suffix value=".yyyy-MM-dd"/>
                          <append value="true"/>
                      </periodic-rotating-file-handler> 
          
                      <logger category="com.myApp">
                          <level name="ALL"/>
                          <handlers>
                              <handler name="log1"/>
                              <handler name="log2"/>
                          </handlers>
                      </logger>
             ...
          </subsystem>
          

           

           

          --

          James R. Perkins

          • 2. Re: JBoss 7 Logging
            Joseph Fouts Novice

            Thanks James I was able to get my sample to work with jboss logging.

             

            When I setup the loggers I edited the standalone.xml directly.  Is this not a good thing or should I be using the console or the web browser?

             

            Thanks.

            • 3. Re: JBoss 7 Logging
              James Perkins Master

              Joseph,

              Editing the XML is not a problem at all. I tend to use the consoles because it shows all the options and I don't have to remember the options for each type of handler.

               

              --

              James R. Perkins

              • 4. Re: JBoss 7 Logging
                leamen li Newbie

                Hi James,

                 

                     I wander how can I create daily log in JBoss 7 ?

                     I used log4j before, it can create a new log file each day (the old logs not been removed), besides, it can create new log file when file size larger than a given max size.

                     Does JBoss 7 logging support such feature? How should I config the standalone.xml if I want the same effect?

                    

                     Thank you.

                • 5. Re: JBoss 7 Logging
                  traian20 Newbie

                  Jboss logging subsystem supports periodic-rotating-file-handler and size-rotating-file-handler.

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

                                  <rotate-size value="5000k"/>

                                  <max-backup-index value="10"/>

                                  <append value="true"/>

                              </size-rotating-file-handler>

                  • 6. Re: JBoss 7 Logging
                    James Perkins Master

                    In the latest upstream latest upstream of the JBoss Log Manager there is a new handler that will roll on date and/or size. I'm not sure when that will get pushed to JBoss AS7 though.

                     

                    Currently you will only be able to roll a log by size or date, but not both. Though if you wanted you could write your own handler, add as a module and configure it through a custom-handler.

                    • 7. Re: JBoss 7 Logging
                      mike just Master

                      I defined a handler log1 to output category com.cate1 messages to log file1.

                       

                      <logger category="com.cate1">
                                      <level name="INFO"/>
                                      <handlers>
                                          <handler name="log1"/>
                                      </handlers>
                      </logger>
                      
                      

                       

                      But I found all this category's messages are also output to CONSOLE. How to disable this output to CONSOLE. I want them to only go to log file1.

                      • 8. Re: JBoss 7 Logging
                        James Perkins Master

                        On your logger you need to add the use-parent-handler attribute and set it to false. That will only process loggers defined as com.cate1 to only process through the log1 handler.

                         

                        <logger category="com.cate1" use-parent-handlers="false">
                            <level name="INFO"/>
                            <handlers>
                                <handler name="log1"/>
                            </handlers>
                        </logger>
                        
                        

                         

                        --

                        James R. Perkins

                        • 9. Re: JBoss 7 Logging
                          mike just Master

                          Thanks James, is there any documentation about the optional attributes?

                          • 10. Re: JBoss 7 Logging
                            James Perkins Master

                            It's not the greatest documentation, but yes it is documented.

                             

                            --

                            James R. Perkins

                            • 11. Re: JBoss 7 Logging
                              mike just Master

                              Thanks James. Sorry that I have another question. I have my root logger including ouput to CONSOLE and logfile. The question is why the log.info() in my code all output to CONSOLE. I can confirm in old version JBoss log.info() in my code only output to logfile handler.

                               

                              <root-logger>
                                              <level name="INFO"/>
                                              <handlers>
                                                  <handler name="CONSOLE"/>
                                                  <handler name="logfile"/>
                                              </handlers>
                              </root-logger>
                              
                              

                               

                               

                              Another question: why cannot using following settings get demo.log.yyyyMMdd format for a daily log output? (Still one demo.log fle after another day) And how long is the period rotation?

                               

                              <periodic-rotating-file-handler name="demo" autoflush="true">
                                              <formatter>
                                                  <pattern-formatter pattern="%d{HH:mm:ss,SSS} %-5p [%c] (%t) %s%E%n"/>
                                              </formatter>
                                              <file relative-to="jboss.server.log.dir" path="../../../../logs/demo.log"/>
                                              <suffix value=".yyyyMMdd"/>
                                              <append value="true"/>
                              </periodic-rotating-file-handler>
                              
                              
                              • 12. Re: JBoss 7 Logging
                                James Perkins Master

                                Thanks James. Sorry that I have another question. I have my root logger including ouput to CONSOLE and logfile. The question is why the log.info() in my code all output to CONSOLE. I can confirm in old version JBoss log.info() in my code only output to logfile handler.

                                 

                                 

                                <root-logger>
                                    <level name="INFO"/>
                                    <handlers>
                                        <handler name="CONSOLE"/>
                                        <handler name="logfile"/>
                                    </handlers>
                                </root-logger>
                                
                                

                                 

                                 

                                It's because you have the CONSOLE handler defined on the root logger I would assume. Could you paste your entire logging subsystem configuration?

                                 

                                 

                                Another question: why cannot using following settings get demo.log.yyyyMMdd format for a daily log output? (Still one demo.log fle after another day) And how long is the period rotation?

                                 

                                <periodic-rotating-file-handler name="demo" autoflush="true">
                                    <formatter>
                                        <pattern-formatter pattern="%d{HH:mm:ss,SSS} %-5p [%c] (%t) %s%E%n"/>
                                    </formatter>
                                    <file relative-to="jboss.server.log.dir" path="../../../../logs/demo.log"/>
                                    <suffix value=".yyyyMMdd"/>
                                    <append value="true"/>
                                </periodic-rotating-file-handler>
                                
                                

                                 

                                This was a bug that was fixed in JBoss Log Manager. If you were to leave the sever up for more than 24 hours it would roll. The change is upstream, just not in any community releases at this point.

                                 

                                --

                                James R. Perkins

                                • 13. Re: JBoss 7 Logging
                                  mike just Master

                                  Thanks, James. Here is my entire subsystem for the logging.

                                   

                                   

                                  <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="demo" autoflush="true">
                                                  <formatter>
                                                      <pattern-formatter pattern="%d{HH:mm:ss,SSS} %-5p [%c] (%t) %s%E%n"/>
                                                  </formatter>
                                                  <file relative-to="jboss.server.log.dir" path="../../../../logs/demo.log"/>
                                                  <suffix value=".yyyyMMdd"/>
                                                  <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="demo"/>
                                                  </handlers>
                                              </root-logger>
                                  • 14. Re: JBoss 7 Logging
                                    James Perkins Master

                                    What you would need to do is define a logger with the category of your logger. Assign the demo handler to that logger and set the use-parent-handler to false. If you also want system log messages to go into the file, then you'll need to keep the demo handler on the root-logger too.

                                     

                                    Should probably look something like this:

                                     

                                    <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="demo" autoflush="true">
                                        <formatter>
                                            <pattern-formatter pattern="%d{HH:mm:ss,SSS} %-5p [%c] (%t) %s%E%n"/>
                                        </formatter>
                                        <file relative-to="jboss.server.log.dir" path="../../../../logs/demo.log"/>
                                        <suffix value=".yyyyMMdd"/>
                                        <append value="true"/>
                                    </periodic-rotating-file-handler>
                                    
                                    
                                    <!-- Only log to the demo handler -->
                                    <logger category="demo.category" use-parent-handlers="false">
                                        <level name="INFO"/>
                                        <handlers>
                                            <handler name="demo"/>
                                        </handlers>
                                    </logger>
                                    
                                    
                                    <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"/>
                                            <!-- Logs all messages to the demo handler -->
                                            <handler name="demo"/>
                                        </handlers>
                                    </root-logger>
                                    
                                    

                                     

                                    --

                                    James R. Perkins

                                    1 2 3 Previous Next