Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

log4j rootlogger turn off logger for some classes

Tags:

java

log4j

how can i configure a log4j.properties with a rootlogger = debug, stdout, logfile
and org.apache.httpclient = debug which goes into the logfile but not the stdout?

raising the rootlogger to info is not acceptable as i have others package at the debug level.

like image 511
zeroin23 Avatar asked Sep 11 '09 15:09

zeroin23


People also ask

Can log4j be disabled?

To Enable or Disable Log4j Logging for an Instant Messaging Component. By default, log4j logging is used for all components for which logging information is generated. To disable log4j logging, set the logging level for the component to OFF in both log4j. conf and log4j.

What is log4j Rootlogger?

The rootlogger is always the logger configured in the log4j. properties file, so every child logger used in the application inherits the configuration of the rootlogger . The logging levels are (from smaller to greater) : ALL, DEBUG, INFO, WARN, ERROR, FATAL, OFF .

How do I customize log4j?

To define a custom log level in code, use the Level. forName() method. This method creates a new level for the specified name. After a log level is defined you can log messages at this level by calling the Logger.


1 Answers

In the log4j.properties file, add the line

log4j.logger.org.apache.httpclient=DEBUG, logfile

to direct the org.apache.httpclient logger output to the logfile appender.

Also include the line

log4j.additivity.org.apache.httpclient=false

to prevent the org.apache.httpclient logger output going to the rootLogger's appenders.

like image 91
Chin Huang Avatar answered Sep 21 '22 20:09

Chin Huang