2 Replies Latest reply on Mar 22, 2013 2:27 PM by jamezp

    Logging into multiple files dinamically with JBoss7

    chemist

      Hi,

       

        I'm analizing the migration of my applications from JBoss 5 to JBoss 7, but having a problem on Logging infrastructure.

       

        My applications, process's multiple services in the same environments.

        For each service I dinamically create a new logger file (not configured, but programatically) and use it (code below).

       

        But using the current Jboss7 configuration with a periodic-rotating-file-handler on my standalone file and org.jboss.logmanager.handlers.FileHandler at logging.properties file I no longer have direct access to RootLogger Appenders.

         I've inspected the RootLogger object returned and (it seems for me that) it's using a LoggerNode instead witch inside has the configured file appender. I've tried to look a API to reach the LoggerNode and haven't found it.

       

        Does anyone knows a way to replicate this log file dinamism at JBoss 7, or maybe some other logging configuration that would allow this functionalities?

       

       

        Follows code for JBoss 5.

       

                      //Get Root Logger and its File Appender

                      Logger mainLogger = Logger.getRootLogger();

                      Appender appender = mainLogger.getAppender("FILE");

       

                      //Create New Appender for new Log file

                      if (fileAppender instanceof DailyRollingFileAppender)

                      {

                          DailyRollingFileAppender newrfa = new DailyRollingFileAppender(fileAppender.getLayout(),

                                                                                         filePath + logName + ".log",

                                                                                         ((DailyRollingFileAppender) fileAppender).getDatePattern());

                          newFileAppender = newrfa;

                      }

       

                      //Copy configuration from Root Loger

                          newFileAppender.setBufferedIO(fileAppender.getBufferedIO());

                          newFileAppender.setBufferSize(fileAppender.getBufferSize());

                          newFileAppender.setEncoding(fileAppender.getEncoding());

                          newFileAppender.setErrorHandler(fileAppender.getErrorHandler());

                          newFileAppender.setImmediateFlush(fileAppender.getImmediateFlush());

                          newFileAppender.setThreshold(fileAppender.getThreshold());

                          newFileAppender.setName(logName);

                          newFileAppender.activateOptions();

                          l.addAppender(newFileAppender);

       

       

                          // Inherit the remaining of the appenders defined in

                          // root, if any

                          Enumeration<?> apps = mainLogger.getAllAppenders();

                          if (apps != null)

                          {

                              while (apps.hasMoreElements())

                              {

                                  Appender a = (Appender) apps.nextElement();

                                  if (!a.getName().equalsIgnoreCase("FILE"))

                                  {

                                      // skip file, already have our own

                                      l.addAppender(a);

                                  }

                              }

                          }

        • 1. Re: Logging into multiple files dinamically with JBoss7
          chemist

          Some update on this issue.

           

          We've tried with JBoss EAP 6.1.0.Alpha, since it's using logging 1.2 and per-deployment logging.

          In this environment and setting log4j.properties in each ear we've made this code to work.

           

          Although this would solve it has the big inconvenience of having to put the log4j properties file in each ear. Considering the solution uses 20+ ears this is a configuration pain if someday we'll have to change the log4j configuration.

           

          So, the question remains, is there a way to access the appenders/LoggerNode on jboss logging, or using per-deployment logging to only configure the log4j on a module?

           

          Regards

          • 2. Re: Logging into multiple files dinamically with JBoss7
            jamezp

            If you're using JBoss EAP 6.1.0.Alpha there is a concept of logging profiles. This sounds like what you might want here. Each profile is it's own logging configuration and allows for runtime changes which the per-deployment logging does not handle.

             

            --

            James R. Perkins