Logging into multiple files dinamically with JBoss7
chemist Mar 20, 2013 3:23 PMHi,
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);
}
}
}