2 Replies Latest reply on Jan 7, 2011 10:49 AM by stephane_

    JBoss AS6 logging , how to configure XMLLayout

    stephane_ Newbie

      Hi

       

      Migrating from 5.1 to 6.

      I am trying to figure out how to configure a log4j appender with XMLLayout with the new logging format

       

      Any pointer or doc would be greatly appreciated .

       

      Thanks

       

      Stephane

        • 1. Re: JBoss AS6 logging , how to configure XMLLayout
          jaikiran pai Master

          Just a FYI - You don't have to use the jboss-logging.xml file to configure your application's logging. You can always use your own log4j.xml file within your application.

          • 2. JBoss AS6 logging , how to configure XMLLayout
            stephane_ Newbie

            After many trial and error I ended up creating a placeholder appender

             

            <periodic-rotating-file-handler

                     file-name="${jboss.server.log.dir}/server.log.xml"

                     name="XMLFILE"

                     autoflush="true"

                     append="true"

                     suffix=".yyyy-MM-dd">  <!-- To roll over at the top of each hour, use ".yyyy-MM-dd-HH" instead -->

             

            <level name="OFF"/>

             

                  <error-manager>

                     <only-once/>

                  </error-manager>

             

                  <formatter>

                     <!-- To revert back to simple stack traces without JAR versions, change "%E" to "%e" below. -->

                     <!-- Uncomment this to get the class name in the log as well as the category

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

                     -->

                     <!-- Uncomment this to log without the class name in the log -->

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

                  </formatter>

               </periodic-rotating-file-handler>

             

            and then I set the layout programmatically in a bean

             

            java.util.logging.Logger logger = java.util.logging.Logger.getLogger("");

                                for (Handler h : logger.getHandlers())

                                {

             

             

                                          // h.setFormatter(new XMLFormatter())

                                          if (h instanceof PeriodicRotatingFileHandler

                                                              && ((PeriodicRotatingFileHandler) h).getFile().getName().contains(".xml"))

                                          {

             

                                                    h.setFormatter(new XMLFormatter());

                                                    h.setLevel(java.util.logging.Level.ALL);

                                                    logger.info("XML Logger initialized");

                                                    break;

                                          }

                                }

             

             

            It works if I deploy my bean after the server is started , however it seem that otherwise application (my bean included) are deployed before the app server switches away from the boot logger , so the boot logger get the configuration but not the main logger ...

            Any way to tell JBoss to switch logging before starting applications ?