Hi,
I have a multi threaded application.
There are multiple task getting created in the application which will log to
a separate log file.
*For each task the log file initialization happens in AbstractTaskComponent
as follows:*
// get the log directory
File taskLogDir =
TaskControllerComponent.getTaskControllerComponent().getTaskLogDirectory();
File taskLogFile = new File( taskLogDir, task.getTskId() + ".log" );
taskLogRejectedFile = new File( taskLogDir, task.getTskId() +
".rejected.rawrecord.log" );
// add a special appender for placing this task's log messages in
its own file
// get the log level of the main logger
Logger rootLogger = LogManager.getRootLogger();
// the custom appender for this task logger
FileAppender appender = null;
try
{
appender = new FileAppender( new PatternLayout( "%m%n" ),
taskLogFile.getAbsolutePath() );
}
catch ( IOException e )
{
log.error( "Error adding custom log appender for task logging",
e );
}
// filter log messages to this appender by only printing messages
generated by threads belonging to the
// same thread group as the main thread, if the thread's group is
the main group then just log
// messages from this thread
if ( runner.getThreadGroup().getParent() != null )
{
appender.addFilter( new ThreadGroupFilter(
runner.getThreadGroup() ) );
}
else
{
appender.addFilter( new ThreadFilter( runner ) );
}
rootLogger.addAppender( appender );
*
Also the logger configuration happens at one time while initiating the
application as follows:*
// get the logging configuration file - must exist
URL logURL = getClass().getResource( "/log4j_server.properties" );
if ( logURL == null )
{
System.out.println( "Could not find log4j_server.properties log
configuration file" );
return;
}
// initialise the logging framework
PropertyConfigurator.configure( logURL );
* The properties set in log4j_server.properties as follows:
*
# general program output:
log4j.rootCategory=INFO,stdout,alog
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%5p [%c] [%t] (%F:%L) - %m%n
# access log output:
log4j.appender.alog=org.apache.log4j.FileAppender
log4j.appender.alog.file=server.log
log4j.appender.alog.append=false
log4j.appender.alog.layout=org.apache.log4j.PatternLayout
log4j.appender.alog.layout.ConversionPattern=%5p [%c] [%t] (%F:%L) - %m%n
log4j.logger.com.azure=TRACE
log4j.logger.net.sf.hibernate=INFO*
Still some times the log getting mixed up(one task log in another task file)
*. But this happens once in a while
I was unable to find in what scenario it is going wrong.
Any help would be appreciated.
Regards,
Pradeep