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 Jeb Scarbrough <je...@hotmail.com> on 2004/01/26 17:57:49 UTC

SMTPAppender

I am wanting to send all logs messags via email when i send POST a certain
key-value pair to my servlet.  In essence, allowing me to see a debug log of
one specific request.  I'm new with log4j and havent found much on this in
the archives.  has anyone tried to do this? is it possible?  would what be a
good starting point to accomplishing something like this?

Thanks.

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


Re: SMTPAppender

Posted by Jeb Scarbrough <je...@hotmail.com>.
Looking at the example code below, I'm a little confused as to how/where the
setSMTPAppender would get called?  Secondly, is it feasible to do something
like the below where the "foo" value gets set from a request parameter?  Can
someone please enlighten me??  Thanks for all the help.

public boolean isTriggeringEvent(LoggingEvent event)  {
  if (event.level.isGreaterOrEqual(Level.FATAL)) {
    return true;
  } else {
    if (app != null) {
      if(MDC.get("foo").equals("bar")) {
        // reset the message content
        app.setBufferSize(0);
        app.setBufferSize(size);
      }
  }
}



----- Original Message ----- 
From: "Roth Marcel" <ma...@softlab.ch>
To: "Log4J Users List" <lo...@logging.apache.org>
Sent: Monday, January 26, 2004 12:00 PM
Subject: Re: SMTPAppender


> Hi Jeb,
>
> a way to do this is via implementing the TriggeringEventEvaluator.
> Try something like this
> cheers,
> Marcel
>
>
/***********************************************************************
>      * SMTP Trigger Event Evaluator
>      */
>     private static class SMTPTriggerEval implements
TriggeringEventEvaluator {
>         SMTPAppender app;
>         public void setSMTPAppender(SMTPAppender app) {
>             this.app = app;
>         }
>         public boolean isTriggeringEvent(LoggingEvent event)  {
>             if (event.level.isGreaterOrEqual(Level.FATAL)) {
>                 return true;
>             } else {
>                 if (app != null) {
>                     // reset the message content
>                     int size = app.getBufferSize();
>                     app.setBufferSize(0);
>                     app.setBufferSize(size);
>                 }
>                 return false;
>             }
>         }
>     }
>
>
>
>
>
> Quoting Jeb Scarbrough <je...@hotmail.com>:
>
> > I am wanting to send all logs messags via email when i send POST a
> > certain
> > key-value pair to my servlet.  In essence, allowing me to see a debug
> > log of
> > one specific request.  I'm new with log4j and havent found much on this
> > in
> > the archives.  has anyone tried to do this? is it possible?  would what
> > be a
> > good starting point to accomplishing something like this?
> >
> > Thanks.
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
> > For additional commands, e-mail: log4j-user-help@logging.apache.org
> >
>
>
>
> Marcel Roth
> Technology Consultant
> Enterprise CRM
> _______________________________
> Softlab AG
> Kanalstrasse 31
> CH-8152 Glattbrugg
> Switzerland
> Telefon    +41 1 809 41 57
> Telefax    +41 1 809 41 42
> Mobile    +41 76 420 02 07
> E-Mail    mailto:marcel.roth@softlab.ch
> Homepage:  http://www.softlab.ch
> _______________________________
>
> ---------------------------------------------------------------------
> 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: SMTPAppender

Posted by Roth Marcel <ma...@softlab.ch>.
Hi Jeb,

a way to do this is via implementing the TriggeringEventEvaluator.
Try something like this
cheers,
Marcel

    /***********************************************************************
     * SMTP Trigger Event Evaluator
     */
    private static class SMTPTriggerEval implements TriggeringEventEvaluator {
        SMTPAppender app;
        public void setSMTPAppender(SMTPAppender app) {
            this.app = app;
        }
        public boolean isTriggeringEvent(LoggingEvent event)  {
            if (event.level.isGreaterOrEqual(Level.FATAL)) {
                return true;
            } else {
                if (app != null) {
                    // reset the message content
                    int size = app.getBufferSize();
                    app.setBufferSize(0);
                    app.setBufferSize(size);
                }
                return false;
            }
        }
    }
 




Quoting Jeb Scarbrough <je...@hotmail.com>:

> I am wanting to send all logs messags via email when i send POST a
> certain
> key-value pair to my servlet.  In essence, allowing me to see a debug
> log of
> one specific request.  I'm new with log4j and havent found much on this
> in
> the archives.  has anyone tried to do this? is it possible?  would what
> be a
> good starting point to accomplishing something like this?
> 
> Thanks.
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
> For additional commands, e-mail: log4j-user-help@logging.apache.org
> 



Marcel Roth
Technology Consultant
Enterprise CRM
_______________________________
Softlab AG
Kanalstrasse 31
CH-8152 Glattbrugg
Switzerland
Telefon    +41 1 809 41 57
Telefax    +41 1 809 41 42
Mobile 	   +41 76 420 02 07
E-Mail 	   mailto:marcel.roth@softlab.ch
Homepage:  http://www.softlab.ch
_______________________________

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