srp
srp

Reputation: 519

Logger is printing the message twice and some times even more for the whole program

private static final Logger logger = Logger.getLogger(filename.class);

logger.debug("logger" + element); 

this line is printing twice and some times more..

this prints as

logger 123
logger 123

(on different lines)

Upvotes: 1

Views: 1751

Answers (2)

cherif narjess
cherif narjess

Reputation: 3

try

BasicConfigurator.resetConfiguration()

after BasicConfigurator.configure() in the method that uses logger

Upvotes: 0

Vikdor
Vikdor

Reputation: 24134

I suspect if multiple loggers are qualifying for this class (where the appender configured for these qualifying loggers should be similar) and each one is printing the message.

A look at your log4j configuration file would help.

Upvotes: 1

Related Questions