logging-log4j-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From c...@apache.org
Subject cvs commit: logging-log4j/src/java/org/apache/log4j/net SMTPAppender.java
Date Wed, 05 Jan 2005 17:42:09 GMT
ceki        2005/01/05 09:42:09

  Modified:    src/java/org/apache/log4j/net SMTPAppender.java
  Log:
  SMTPAppender now takes advantage of the poweful new features in Joran, in particular the
capabilty to configure appeder sub-components.
  
  Revision  Changes    Path
  1.44      +30 -36    logging-log4j/src/java/org/apache/log4j/net/SMTPAppender.java
  
  Index: SMTPAppender.java
  ===================================================================
  RCS file: /home/cvs/logging-log4j/src/java/org/apache/log4j/net/SMTPAppender.java,v
  retrieving revision 1.43
  retrieving revision 1.44
  diff -u -r1.43 -r1.44
  --- SMTPAppender.java	4 Jan 2005 19:56:50 -0000	1.43
  +++ SMTPAppender.java	5 Jan 2005 17:42:09 -0000	1.44
  @@ -32,13 +32,13 @@
   import org.apache.log4j.AppenderSkeleton;
   import org.apache.log4j.Layout;
   import org.apache.log4j.Level;
  -import org.apache.log4j.LogManager;
   import org.apache.log4j.helpers.CyclicBuffer;
   import org.apache.log4j.helpers.OptionConverter;
   import org.apache.log4j.pattern.PatternConverter;
   import org.apache.log4j.pattern.PatternParser;
   import org.apache.log4j.rule.ExpressionRule;
   import org.apache.log4j.rule.Rule;
  +import org.apache.log4j.spi.ComponentBase;
   import org.apache.log4j.spi.LoggingEvent;
   import org.apache.log4j.spi.TriggeringEventEvaluator;
   
  @@ -85,7 +85,6 @@
     private boolean locationInfo = false;
     protected CyclicBuffer cb = new CyclicBuffer(bufferSize);
     protected MimeMessage msg;
  -  private String expression;
     protected TriggeringEventEvaluator evaluator;
     private PatternConverter subjectConverterHead;
     
  @@ -319,29 +318,6 @@
     }
     
     /**
  -   * Returns the expression
  -   * 
  -   * @return expression
  -   */
  -  public String getExpression() {
  -    return expression;
  -  }
  -  
  -  /**
  -   * Set an expression used to determine when the sending of an email is triggered.
  -   * 
  -   * Only use an expression to evaluate if the 'evaluatorClass' param is not provided.
  -   * @param expression
  -   */
  -  public void setExpression(String expression) {
  -    
  -    if (evaluator instanceof DefaultEvaluator) {
  -      this.expression = expression;
  -      evaluator = new DefaultEvaluator(expression);
  -    }
  -  }
  -
  -  /**
        Returns value of the <b>Subject</b> option.
      */
     public String getSubject() {
  @@ -415,13 +391,16 @@
     }
   
     /**
  -     The <b>EvaluatorClass</b> option takes a string value
  -     representing the name of the class implementing the {@link
  -     TriggeringEventEvaluator} interface. A corresponding object will
  -     be instantiated and assigned as the triggering event evaluator
  -     for the SMTPAppender.
  +   * The <b>EvaluatorClass</b> option takes a string value representing the

  +   * name of the class implementing the {@link TriggeringEventEvaluator} 
  +   * interface. A corresponding object will be instantiated and assigned as 
  +   * the triggering event evaluator for the SMTPAppender.
  +   * 
  +   * @deprecated replaced by {@link #setEvaluator}.
      */
     public void setEvaluatorClass(String value) {
  +    getLogger().warn("The SMPTAppender.setEvaluatorClass is deprecated.");
  +    getLogger().warn("It has been replaced with the more powerful SMPTAppender.setEvaluator
method.");
       OptionConverter oc = new OptionConverter(this.repository);
       evaluator =
         (TriggeringEventEvaluator) oc.instantiateByClassName(
  @@ -429,6 +408,14 @@
     }
   
     /**
  +   * Set {@link TriggeringEventEvaluator} for this instance of SMTPAppender.
  +   */
  +  public void setEvaluator(TriggeringEventEvaluator evaluator) {
  +    this.evaluator = evaluator;
  +  }
  +
  +
  +  /**
        The <b>LocationInfo</b> option takes a boolean value. By
        default, it is set to false which means there will be no effort
        to extract the location information related to the event. As a
  @@ -470,17 +457,24 @@
   }
   
   
  -class DefaultEvaluator implements TriggeringEventEvaluator {
  +class DefaultEvaluator extends ComponentBase implements TriggeringEventEvaluator {
   
     private Rule expressionRule;
  +  private String expression;
     
     public DefaultEvaluator() {}
     
  -  public DefaultEvaluator(String expression) {
  -    try {
  -      expressionRule = ExpressionRule.getRule(expression);
  -    } catch (IllegalArgumentException iae) {
  -      LogManager.getLogger(SMTPAppender.class).error("Unable to use provided expression
- falling back to default behavior (trigger on ERROR or greater severity)", iae);
  +  public void setExpression(String expression) {
  +    this.expression = expression;
  +  }
  +  
  +  public void activateOptions() {
  +    if(expression != null) {
  +      try {
  +        expressionRule = ExpressionRule.getRule(expression);
  +      } catch (IllegalArgumentException iae) {
  +        getLogger().error("Unable to use provided expression - falling back to default
behavior (trigger on ERROR or greater severity)", iae);
  +      }
       }
     }
     
  
  
  

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


Mime
View raw message