How to disable log4j logging from Java code

Posted by Erel Segal Halevi on Stack Overflow See other posts from Stack Overflow or by Erel Segal Halevi
Published on 2012-01-03T07:56:39Z Indexed on 2012/12/19 5:03 UTC
Read the original article Hit count: 262

Filed under:
|

I use a legacy library that writes logs using log4j. My default log4j.properties file directs the log to the console, but in some specific functions of my main program, I would like to disable logging altogether (from all classes).

I tried this:

Logger.getLogger(BasicImplementation.class.getName()).setLevel(Level.OFF);

where "BasicImplementation" is one of the main classes that does logging, but it didn't work - the logs are still written to the console.

Here is my log4j.properties:

log4j.rootLogger=warn, stdout
log4j.logger.ac.biu.nlp.nlp.engineml=info, logfile
log4j.logger.org.BIU.utils.logging.ExperimentLogger=warn

log4j.appender.stdout = org.apache.log4j.ConsoleAppender
log4j.appender.stdout.layout = org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern = %-5p %d{HH:mm:ss} [%t]: %m%n

log4j.appender.logfile = ac.biu.nlp.nlp.log.BackupOlderFileAppender
log4j.appender.logfile.append=false
log4j.appender.logfile.layout = org.apache.log4j.PatternLayout
log4j.appender.logfile.layout.ConversionPattern = %-5p %d{HH:mm:ss} [%t]: %m%n
log4j.appender.logfile.File = logfile.log

© Stack Overflow or respective owner

Related posts about java

Related posts about log4j