Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why are duplicate messages being logged

I'm new to log4cplus. I have the following configuration:

log4cplus.rootLogger=TRACE, STDOUT 

log4cplus.logger.zios.utl.Thread=DEBUG, STDOUT

log4cplus.appender.STDOUT=log4cplus::ConsoleAppender
log4cplus.appender.STDOUT.layout=log4cplus::PatternLayout
log4cplus.appender.STDOUT.layout.ConversionPattern=%d{%H:%M:%S} [%t] - %m%n

which I load with the following code:

try {
    log4cplus::PropertyConfigurator::doConfigure("log4cplus.properties");
} catch (...) {
    cout << "exception occured while opening log4cplus.properties" << endl;
}

It loads without incident but whenever I log something, I get two messages appearing in my log. For example, I log using this code:

Logger log = Logger::getInstance("zios.utl.Thread");
LOG4CPLUS_DEBUG(log, "Thread created");

and what appears in the log is:

17:10:48 [3075459952] - Thread created
17:10:48 [3075459952] - Thread created

Any idea why this is happening?

like image 762
DaveR Avatar asked Oct 21 '22 02:10

DaveR


1 Answers

You have one appender and you use it twice, for two loggers:

log4cplus.rootLogger=TRACE, STDOUT 
log4cplus.logger.zios.utl.Thread=DEBUG, STDOUT

This means that the appender is attached to root logger and zios.utl.Thread logger.

like image 172
wilx Avatar answered Oct 24 '22 03:10

wilx