Hi there,
I am working on server which used thread pool to process each client request by separate dedicated thread.
My intention was each thread ( of thread pool ) have its own logger and hence all client processed by that thread must be logged in corresponding thread specific logger.
My problem is that logger merging log content with other logger content, my doubt is Logger.getLogge r(...) function return wrong logger object.
I am creating and configuring logger at run time using following function.
where:
sLoggerName : Current thread name ( Thread.currentT hread.getName() )
m_sFilePath : log file path
m_sExt : log file extention
m_layout : static layout object
for example logger for thread 5 wirtes log in file for thread 8 and so on .....
Is there any thing I am missing in code ????
note: I have used java's executor server for thread pooling
log4j.property ( for root logger )
pleas suggest, your help make me happy,
Thank you,
Abhinay
I am working on server which used thread pool to process each client request by separate dedicated thread.
My intention was each thread ( of thread pool ) have its own logger and hence all client processed by that thread must be logged in corresponding thread specific logger.
My problem is that logger merging log content with other logger content, my doubt is Logger.getLogge r(...) function return wrong logger object.
I am creating and configuring logger at run time using following function.
where:
sLoggerName : Current thread name ( Thread.currentT hread.getName() )
m_sFilePath : log file path
m_sExt : log file extention
m_layout : static layout object
Code:
public static Logger getLogger( String sLoggerName )throws IOException { boolean bLoggerExists = false; if(LogManager.exists(sLoggerName) != null) bLoggerExists = true; Logger logger = Logger.getLogger(sLoggerName); if( !bLoggerExists ) { //Logger is not exists so create appender for logger String sFileName = m_sFilePath + sLoggerName + m_sExt; RollingFileAppender appender = new RollingFileAppender(m_layout, sFileName, true ); appender.setMaxBackupIndex( m_iMaxBufferIndex ); appender.setMaxFileSize( m_sLogMaxFileSize ); logger.addAppender( appender ); logger.setLevel( m_logLevel ); logger.setAdditivity(false); } return logger; }
Is there any thing I am missing in code ????
note: I have used java's executor server for thread pooling
log4j.property ( for root logger )
Code:
# Category Configuration log4j.rootLogger=INFO,Konsole,Roll # Console Appender Configuration log4j.appender.Konsole=org.apache.log4j.ConsoleAppender log4j.appender.Konsole.layout=org.apache.log4j.PatternLayout # Date Format based on ISO8601 : %d log4j.appender.Konsole.layout.ConversionPattern=%d [%t] %5p %c %m%n # Roll Appender Configuration log4j.appender.Roll=org.apache.log4j.RollingFileAppender log4j.appender.Roll.File=D\:/4YsClient/Log/ErrorFileList.log log4j.appender.Roll.MaxFileSize=100MB log4j.appender.Roll.MaxBackupIndex=10 log4j.appender.Roll.layout=org.apache.log4j.PatternLayout # Date Format based on ISO8601 : %d log4j.appender.Roll.layout.ConversionPattern=%d [%t] %p (%F:%L) %m%n
pleas suggest, your help make me happy,
Thank you,
Abhinay
Comment