2 Replies Latest reply on Aug 16, 2011 5:04 AM by Richard Clarke

    Question about logging in AS 7

    Richard Clarke Newbie

      Hi,

       

      I am trying to setup logging for an application which should log to 3 separate log files;

       

      1/ server.log - normal info/debug messages etc.

      2/ xml log -  a separate log file to log XML transmissions to and from web services we connect to

      3/ mail.log - another log file which logs mail messages sent out by our application.

       

      The above is working and the correct logs are being used,for the xml and mail messages, however the server.log and console are logging all messages to all three logs (so my console is filling up with XML and mail transcripts defeating the whole purpose of having these three separate log files).

       

       

      I have the logs defined like this...

       

      protected static Logger xmlLog = Logger.getLogger(PiscesXMLLogger);

       

      And am using the following output instructions..

       

      xmlLog.info("-------------------------- XML received ------------------------------- ");

       

      The relevant parts of my logging config are shown below;

      I have 3 file handlers for the 3 log files, plus a console handler, plus a root logger and 2 further loggers for the xml and mail logs.

      Can anyone explain how to modify this to remove the xml and mail log entries from the server log and console?

      Much appreciated.

       

       

      <periodic-rotating-file-handler

               file-name="d:/log/server.log"

               name="FILE"

               autoflush="true"

               append="true"

               suffix=".yyyy-MM-dd">

            <error-manager>

               <only-once/>

            </error-manager>

            <formatter>

               <pattern-formatter pattern="%d %-5p [%c] (%t) %s%E%n"/>

            </formatter>

         </periodic-rotating-file-handler>

       

         <periodic-rotating-file-handler

               file-name="d:/log//xml.log"

               name="XMLLOG"

               autoflush="true"

               append="false"

               suffix=".yyyy-MM-dd">

            <error-manager>

               <only-once/>

            </error-manager>

            <formatter>

               <pattern-formatter pattern="%d %-5p [%c] (%t) %s%E%n"/>

            </formatter>

         </periodic-rotating-file-handler>

       

         <periodic-rotating-file-handler

               file-name="d:/log//mail.log"

               name="MAILLOG"

               autoflush="true"

               append="false"

               suffix=".yyyy-MM-dd">

            <error-manager>

               <only-once/>

            </error-manager>

            <formatter>

               <pattern-formatter pattern="%d %-5p [%c] (%t) %s%E%n"/>

            </formatter>

         </periodic-rotating-file-handler>

       

         <console-handler name="CONSOLE" autoflush="true" target="System.out">

            <error-manager>

               <only-once/>

            </error-manager>

            <level name="INFO"/>

            <formatter>

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

            </formatter>

         </console-handler>

       

       

       

         <logger category="PiscesXMLLogger">

            <level name="DEBUG"/>

            <handlers>

               <handler-ref name="XMLLOG"/>

            </handlers>

         </logger>

       

       

         <logger category="mailLogger">

            <level name="DEBUG"/>

            <handlers>

               <handler-ref name="MAILLOG"/>

            </handlers>

         </logger>

       

         <root-logger>

            <level name="${jboss.server.log.threshold:INFO}"/>

            <handlers>

               <handler-ref name="CONSOLE"/>

               <handler-ref name="FILE"/>

            </handlers>

         </root-logger>

        • 1. Re: Question about logging in AS 7
          jaikiran pai Master

          The loggers are hierarchical and ultimately end up at the root-logger. As a result, the handlers configured for the root logger (in this case the CONSOLE and FILE) will also be fed the log messages and they too will log them.

           

          If you want to disable this behaviour and disable the specific logger(s) from using the parent handlers, then set use-parent-handlers attribute to false. See the JBOSS_HOME/docs/schema/jboss-logging.xsd for the details. Here's an example:

           

          <logger category="PiscesXMLLogger" use-parent-handlers="false">
                <level name="DEBUG"/>
                <handlers>
                   <handler-ref name="XMLLOG"/>
                </handlers>
             </logger>
          
          • 2. Re: Question about logging in AS 7
            Richard Clarke Newbie

            Jaikiran,

            That did it - nice one.

            Thanks again!

            Rich