You are viewing a plain text version of this content. The canonical link for it is here.
Posted to log4j-user@logging.apache.org by Sergio <se...@strategos.com.br> on 2008/07/21 22:57:18 UTC
Suppress specific Exception
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?
Thanks in advance,
S
---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-user-help@logging.apache.org
RE: Suppress specific Exception
Posted by Scott Deboy <sd...@comotivsystems.com>.
If you're using log4j 1.2.15 with the log4j extras companion, you can
use an ExpressionFilter and exclude events using this expression:
EXCEPTION exists
To exclude all exceptions
Or
EXCEPTION ~= org.hibernate.ObjectNotFoundException
To exclude only exceptions with that string in the exception text
Extras companion available here:
http://logging.apache.org/log4j/companions/extras/index.html
Here's expressionFilter:
https://svn.apache.org/repos/asf/logging/site/trunk/docs/log4j/companion
s/extras/apidocs/org/apache/log4j/filter/ExpressionFilter.html
Scott Deboy
Principal Engineer
COMOTIV SYSTEMS
111 SW Columbia Street Ste. 950
Portland, OR 97201
Office: 503.224.7496
Direct Line: 503.821.6482
Cell: 503.997.1367
Fax: 503.222.0185
sdeboy@comotivsystems.com
www.comotivsystems.com
-----Original Message-----
From: Sergio [mailto:sergio@strategos.com.br]
Sent: Monday, July 21, 2008 1:57 PM
To: log4j-user@logging.apache.org
Subject: Suppress specific Exception
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?
Thanks in advance,
S
---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-user-help@logging.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-user-help@logging.apache.org
Re: Suppress specific Exception
Posted by Sergio <se...@strategos.com.br>.
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: log4j-user-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-user-help@logging.apache.org
Re: Suppress specific Exception
Posted by Thorbjørn Ravn Andersen <th...@gmail.com>.
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(...)
--
Thorbjørn
---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-user-help@logging.apache.org