mwangi
mwangi

Reputation: 1626

Exempt a given class not to write into my log file using Log4J properties file

I am using log4j to do my logging.

I lately added a library (Connection pooling lib called DBPool) and it is producing a lot of output to my log file. The log file reaches its max file size in less than 30minutes.

The excessive output to my log file is also making my debugging very hard because I cannot see easily locate my lines of interest in the log file is hindering me from debugging my code.

My question is, How do I exempt a given class from writing in my log file using log4j?

Here is my log4.properties file's contents.

log4j.rootCategory=DEBUG, dailyApp
log4j.rootCategory=DEBUG, dailyApp 
log4j.appender.A1=org.apache.log4j.ConsoleAppender 
log4j.appender.A1=org.apache.log4j.ConsoleAppender   
log4j.appender.A1.layout=org.apache.log4j.PatternLayout
log4j.appender.A1.layout.ConversionPattern=%d %-4r [%t] %-5p %c{2} %x - %m%n
log4j.appender.dailyApp=org.apache.log4j.RollingFileAppender

log4j.appender.dailyApp.File=logs/myLog.log

log4j.appender.dailyapp.MaxFileSize=1024KB
log4j.appender.dailyApp.MaxBackupIndex=5

log4j.appender.dailyApp.layout=org.apache.log4j.PatternLayout
log4j.appender.dailyApp.layout.ConversionPattern=%d %-4r [%t] %-5p %c{2} %x - %m%n
log4j.logger.httpclient=INFO
log4j.logger.org.apache.commons.httpclient=INFO

The class I do not want to log into logs/myLog.log is snaq.db.ConnectionPool

Thanks.

Upvotes: 0

Views: 458

Answers (3)

Andreas Dolk
Andreas Dolk

Reputation: 114837

Adding this line to the configuration file should work:

log4j.snap.db.ConnectionPool=ERROR

This will not disable logging for instances of this class but set the minimum level to error.

Upvotes: 3

Johannes Wachter
Johannes Wachter

Reputation: 2735

As far as I know the following should work, like with the two INFO levels at the bottom of your configuration.

log4j.logger.some.package.name=OFF

Upvotes: 4

JoseK
JoseK

Reputation: 31371

Adding this line

log4.logger.snaq.db = ERROR

should help

Upvotes: 4

Related Questions