my dog learned polymorphism*
The moose likes Java in General and the fly likes log4j: assigning logging level per appender Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "log4j: assigning logging level per appender" Watch "log4j: assigning logging level per appender" New topic
Author

log4j: assigning logging level per appender

David Irwin
Ranch Hand

Joined: Mar 25, 2004
Posts: 82
All,

I use log4j extensively in my application. I'm wondering if there's a way to set the logging level based on the appendering being used. For example, my rolling file appender I would like to set to debug logging level, while my console appender I would like to set to info, and my smtp appender to fatal.

I've looked through the log4j manual and while I can set the logging level based on a specific class package (i.e. foo.bar.com set to a different logging level than my root logger), I can't figure out a way to set the logging level based on the appender. Am I missing something?

Thanks,
Dave
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8

I don't think so. I just looked at the API documentation. The Logger class has a setLevel() method and the Appender class doesn't.

You could write an org.apache.log4j.spi.Filter object that denies logging events of whatever level you want to filter out, and add that to the appender in question.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: log4j: assigning logging level per appender
 
Similar Threads
log4j:WARN No appenders could be found for logger
Multiple context logging JBoss-Tomcat
Server loggng with log4j Tomcat 6.x
Java Logging and concurrent users
Writing File in Java