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 {
   // ...

   @Override
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)
                   return;
           }
       }
super.append(event);
   }

   // ...
}

And on my configuration file:

log4j.appender.file=my.package.ExceptionFilterFileAppender
log4j.appender.file.File=general.log
log4j.appender.file.layout=org.apache.log4j.PatternLayout
log4j.appender.file.layout.ConversionPattern=%d{ABSOLUTE} %5p %c{1}:%L - %m%n
log4j.appender.file.ExceptionsToSuppress=org.hibernate.ObjectNotFoundException

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: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to