logging-log4j-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Sergio <ser...@strategos.com.br>
Subject Re: Suppress specific Exception
Date Tue, 22 Jul 2008 15:35:44 GMT
Thanks! I got it working the way you told me to do. Anyway, I found that 
is possible to use filters to accomplish the same thing, but you need to 
use a xml configuration file instead of properties file. Just for the 
records, here is what I did to suppress exceptions from my log file:

public class ExceptionFilterFileAppender extends 
org.apache.log4j.FileAppender {
    // ...

    public void append(LoggingEvent event) {       
        ThrowableInformation ti = event.getThrowableInformation();

        if (ti != null) {
            Throwable t = ti.getThrowable();
            if (t != null) {
                String className = t.getClass().getName();

                if (exceptionsToSuppress != null && 
exceptionsToSuppress.indexOf(className) != -1)

    // ...

And on my configuration file:

log4j.appender.file.layout.ConversionPattern=%d{ABSOLUTE} %5p %c{1}:%L - 

Later on I plan to use xml configuration file and use a filter instead 
of subclassing an Appender class.

Thorbjørn Ravn Andersen wrote:
> Sergio skrev  den 21-07-2008 22:57:
>> Hi,
>> I have the annoying uncatchable ObjectNotFoundException from 
>> hibernate on my log with big stack traces. I want to completely 
>> suppress this exception from my log. I tried to find something about 
>> filters on Log4J, but I think that is not the correct way to do it. 
>> Any ideas on how I can suppress an exception from being add to the log?
> Subclass the appender in question and do your filtering before calling 
> super(...)

To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-user-help@logging.apache.org

View raw message