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 tyson magney <tm...@gmail.com> on 2007/03/28 01:27:10 UTC

Conditionaly sending email with Log4j

I have an electronic forms processing application that releases documents to
a database.  When an exception occurs, the app needs to send an email to an
admin depending on which form threw the exception.  I already have lo4j in
place with an SMTP appender configured.  What I cannot figure out is, how do
I conditionaly send emails?  I could setup multiple SMTP appenders, but how
would log4j know which appender to use when a particular form throws an
exception?

The best solution I can come up with, is to subclass SMTPAppender and
override sendBuffer().  When sendBuffer is called, the appender name would
be compared to a value stored in the MDC. If a match  is found then
super.sendBuffer would be called.  Cany anyone think of a better solution?

Thanks.

- Tyson

Re: Conditionaly sending email with Log4j

Posted by James Stauffer <st...@gmail.com>.
One option would be to have separate loggers per form and then only
attach the appender to the desired logggers.  Note that SMTPAppender
only sends email when it encounters and error (or higher) level
logger..

On 3/27/07, tyson magney <tm...@gmail.com> wrote:
> I have an electronic forms processing application that releases documents to
> a database.  When an exception occurs, the app needs to send an email to an
> admin depending on which form threw the exception.  I already have lo4j in
> place with an SMTP appender configured.  What I cannot figure out is, how do
> I conditionaly send emails?  I could setup multiple SMTP appenders, but how
> would log4j know which appender to use when a particular form throws an
> exception?
>
> The best solution I can come up with, is to subclass SMTPAppender and
> override sendBuffer().  When sendBuffer is called, the appender name would
> be compared to a value stored in the MDC. If a match  is found then
> super.sendBuffer would be called.  Cany anyone think of a better solution?
>
> Thanks.
>
> - Tyson
>


-- 
James Stauffer        http://www.geocities.com/stauffer_james/
Are you good? Take the test at http://www.livingwaters.com/good/

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