Title: RE: SMTPAppender buffer size

Thanks. I understand better now.

So to send a mail with 40 logs of ERROR priority level, and no logs of other priority, the best way should be :

        <appender name="MAIL" class="org.appache.log4j.net.SMTPAppender">
                ...
                <param name="BufferSize" value="40" />
                <param name="EvaluatorClass" value="TriggerAfter40LogEvents" />

                <filter class="org.apache.log4j.varia.PriorityMatchFilter">
                    <param name="PriorityToMatch" value="error" />
              <param name="AcceptOnMatch" value="true" />
                </filter>
        </appender>

The class TriggerAfter40LogEvents is given by Jim Moore (in this thread) :

public TriggerAfter40LogEvents implements TriggeringEventEvaluator {
  private int count;
  public TriggerAfter40LogEvents() {
    count = 0;
  }
  public boolean isTriggeringEvent(LoggingEvent event) {
    if (count == 39) {
      count = 0;
      return true;
    }
    else {
      count++;
      return false;
    }
  }
}


The parameter BufferSize with value 40 is optional. It's just because there will never be more than 40 elements in the buffer. So the default size (512) is too big.


If we have a category defined on a lower priority than ERROR :

        <category name="C1" >
                <priority value="info" />
                <appender-ref ref="MAIL" />
        </category>

then the filter (PriorityMatchFilter) must be given into the parameters, else we could have, in each mail, 40 ERROR logs and N other priority logs (we want N=0).

Is that solution (filter + evaluator) good ?

-----Message d'origine-----
De : Ceki Gülcü [mailto:[EMAIL PROTECTED]]
Envoyé : mardi 6 février 2001 11:09
À : LOG4J Users Mailing List
Objet : RE: SMTPAppender buffer size



Hi Simon,

The BufferSize represents the maximum number of messages that can be accumulated and sent when the triggering event occurs.

The triggering event is by defaut an error or fatal message. This can be changed. For example, if you set the buffer size to 3 and the sequence of logs is:

debug  <-- message 1
debug  <-- message 2
debug  <-- message 3
warn   <-- message 4
info   <-- message 5
error  <-- message 6 (triggering event)

Then, messages 4,5 and 6 will be included in the email generated by the SMTPAppender. If the buffer size was 5, then messages 2,3,4,5 and 6 would have been included. If the buffer size were 10'000, then messages 1 through 6 would be included. Does that help? Ceki


At 10:58 06.02.2001 +0100, you wrote:
>Thanks for your idea.
>But does it mean that the BufferSize parameter does not work ? Or maybe I don't understand its goal...
>
>Simon BRANDHOF 
>-----Message d'origine-----
>De : Jim Moore [mailto:[EMAIL PROTECTED]]
>Envoyé : lundi 5 février 2001 23:33
>À : 'LOG4J Users Mailing List'
>Objet : RE: SMTPAppender buffer size
>
>Hacking something out, it would be:

>public TriggerAfter40LogEvents implements TriggeringEventEvaluator {
>  private int count;
>  public TriggerAfter40LogEvents() {
>    count = 0;
>  }
>  public boolean isTriggeringEvent(LoggingEvent event) {
>    if (count == 39) {
>      count = 0;
>      return true;
>    }
>    else {
>      count++;
>      return false;
>    }
>  }
>}

>Then use that as your trigger.  Obviously, the above isn't very maintainable, but you get the idea.
>
>-Jim Moore
>"Pinky, you've left the lens cap of your mind on again." - The Brain.
>-----Original Message-----
>From: BRANDHOF Simon [mailto:[EMAIL PROTECTED]]
>Sent: Monday, February 05, 2001 6:38 AM
>To: '[EMAIL PROTECTED]'
>Subject: SMTPAppender buffer size
>
>Hi,
>
>I hava problems using the 'BufferSize' option of the SMTPAppender. 
>Whatever its value, it always sends one mail by log. 
>Does anyone know how could I send a mail after only N logs ?
>
>Thanks

----
Ceki Gülcü           e-mail: [EMAIL PROTECTED] (preferred)
av. de Rumine 5              [EMAIL PROTECTED]
CH-1005 Lausanne         
Switzerland            Tel: ++41 21 351 23 15


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to