Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to disable loggers of a class or of whole package?

I am using Apache Commons Logging ™. For now I wanted to use SimpleLog implementation, but when I changed the level, loggers from the libraries came out. I want it to turn them off.

Is there a easy way to change log level for whole package (can Log4j do that)?

I have tried to set

org.apache.commons.logging.simplelog.log.foo=fatal

in the property files to disable (setting to fatal is OK) foo logger, but it doesn't work (foo is a name of logger that appears in output : [INFO] foo - Message).

like image 806
Damian Avatar asked Feb 11 '11 19:02

Damian


People also ask

How do I disable slf4j?

To disable this behavior, you must add a logback configuration file called logback. xml in your java classpath root. You can download this minimal logback. xml file and add it in the src/main/resources directory for a maven project or beside fr directory for a simple java project.

How do I disable Log4j2?

You can control the internal logging Log4j2 prints to the console with the status attribute at the top of the configuration file. I would recommend that you switch off the verbose debug -level logging but keep the warn and error level logging so you get informed when something goes wrong.


2 Answers

In Log4j you can specify a logging level for specified package, class or logger identified by string. You just simply write this in log4j.properties file:

log4j.logger.<your package> = DEBUG|INFO|OFF|WARN... 
like image 171
Arek Avatar answered Sep 22 '22 02:09

Arek


You should use:

log4j.logger.foo = OFF 

Please note that "foo" does not need to be a package, or a class, but is an arbitrary String. We e.g. have a logger named "SQL" that is called from many classes.

like image 43
Daniel Avatar answered Sep 22 '22 02:09

Daniel