This week's book giveaway is in the Design forum.
We're giving away four copies of Building Microservices and have Sam Newman on-line!
See this thread for details.
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 Building Microservices this week in the Design 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
Sheriff

Joined: Oct 14, 2005
Posts: 19728
    
  10

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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: log4j: assigning logging level per appender
 
It's not a secret anymore!