Skip to content

faq 111411605

Billy Charlton edited this page Sep 5, 2018 · 2 revisions

log4j setLevel access

by Robert Fitzgerald on 2017-08-18 00:13:51


Hi!

I'm working with the MATSim library and want to suppress INFO logging. Is there a way to access Config's log4j instance and set it's log level? Right now I am using the following work-around in my driver class:

Logger.getRootLogger.setLevel(Level.WARN)

But, with this solution, I can't use my own logger to issue INFO related to my experiments.

Thank you for reading,

Rob


Comments: 1


Re: log4j setLevel access

by Marcel Rieser on 2017-08-18 07:30:24

By default, each class in MATSim uses it's own Logger, so that it's level can be set individually.

In your code, you change the level of the root logger which is used by default for all classes. To change the settings just for a single class, e.g. Config, you can use the following code:

Logger.getLogger(Config.class).setLevel(Level.WARN);


In the log file, the class name is typically shown after the log level. Example:

2017-08-18 09:27:53,264  INFO MatsimXmlParser:155 starting to parse xml from url ....

This line shows that the logger responsible for this line is the class `MatsimXmlParser`. So to configure the logger responsible for this line, you could use 

Logger.getLogger(MatsimXmlParser.class).setLevel(Level.WARN);
Clone this wiki locally