Howdy,

>Can you use these appenders as part of catching exceptions from within
>the Code? That is, if you catch a certain exception that is going to be
>logged, you set isTriggeringEvent on it and Log4J can then do what
needs
>to be done?

The way it works is like this:
- You define the appender (SMTP appender for emails)
- You define the class (a java class) of the TriggeringEventEvaluator
- The above two can be done in a configuration file, no coding needed
- You write the triggering event evaluator (have to write java for this)
- The application uses log4j to do its logging normally.  It doesn't
need to know about the triggering event evaluator at all.  Log4j will
automatically evaluate events sent to the mail appender and decide
whether to send emails or not.

>Using the SMTPAppender to email it my pager would be plenty.

Then you're pretty much all set.  I'll even attach a simple string match
evaluator for use as an example.  (Yes, I'm bored today ;))

Yoav Shapira
Millennium ChemInformatics



This e-mail, including any attachments, is a confidential business communication, and 
may contain information that is confidential, proprietary and/or privileged.  This 
e-mail is intended only for the individual(s) to whom it is addressed, and may not be 
saved, copied, printed, disclosed or used by anyone else.  If you are not the(an) 
intended recipient, please immediately delete this e-mail from your computer system 
and notify the sender.  Thank you.

public class StringMatchEvaluator
  implements TriggeringEventEvaluator {
  /**
   * Interface method.
   * Returns true if the given
   * event should trigger 
   * the appender.
   *
   * This implementation checks for
   * the presence of the String "blah".
   * Add a setter for blah to customize
   * the match string.
   *
   * @param event The logging event
   * @return boolean
   */
   public boolean isTriggeringEvent(LoggingEvent event) {
     if(event == null) {
       return false;
     }

     String eventMessage = event.getMessage();
     if((eventMessage != null) &&
        (eventMessage.indexOf("blah") > -1)) {
       return true;
     }

     ThrowableInformation ti = event.ThrowableInformation();
     if(ti != null) {
       String[] stackTrace = ti.getThrowableStrRep();
       if(stackTrace != null) {
         for(int i = 0; i < stackTrace.length; i++) {
           if(stackTrace[i].indexOf("blah") > -1) {
             return true;
           }
         }
       }
     }

     return false;
   }
}

// End of class: StringMatchEvaluator.java
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to