[logback-dev] svn commit: r630 - logback/trunk/logback-access/src/main/java/ch/qos/logback/access/net

noreply.seb at qos.ch noreply.seb at qos.ch
Fri Oct 6 17:26:07 CEST 2006


Author: seb
Date: Fri Oct  6 17:26:07 2006
New Revision: 630

Modified:
   logback/trunk/logback-access/src/main/java/ch/qos/logback/access/net/SMTPAppender.java

Log:
- modified default triggering behaviour
- updated javadoc accordingly

Modified: logback/trunk/logback-access/src/main/java/ch/qos/logback/access/net/SMTPAppender.java
==============================================================================
--- logback/trunk/logback-access/src/main/java/ch/qos/logback/access/net/SMTPAppender.java	(original)
+++ logback/trunk/logback-access/src/main/java/ch/qos/logback/access/net/SMTPAppender.java	Fri Oct  6 17:26:07 2006
@@ -29,8 +29,12 @@
  * keeps memory requirements at a reasonable level while still delivering useful
  * application context.
  * <p> 
- * By default, the email is sent everything an event has a status code of 
- * <em>500 (server error) or higher</em>.
+ * By default, the email is sent everytime an event has a status code of 
+ * <em>500 (server error) or higher</em>. In order not to flood one's mailbox, 
+ * an email will be sent only if the previous email was sent more that 24 hours ago.
+ * <p>
+ * This behaviour can be easily bypassed either by modifying this class, or by
+ * imlementing a new <code>TriggeringPolicy</code>.
  * <p>
  * @author Ceki G&uuml;lc&uuml;
  * @author S&eacute;bastien Pennec
@@ -117,16 +121,30 @@
   private boolean started;
 
   private static final Integer TRIGGERING_STATUS_CODE = 500;
+  private static final long ONE_DAY = 1000*60*60*24;
+  private static long LAST_TRIGGER_DATE = 0L;
+  
+  
   /**
    * Is this <code>event</code> the e-mail triggering event?
    * 
    * <p>
    * This method returns <code>true</code>, if the event status code
    * is 500 (server error) or higher. Otherwise it returns <code>false</code>.
+   * 
+   * Once an email is sent, the next one will not be sent unless a certain amount
+   * of time passed.
    */
   public boolean isTriggeringEvent(File file, Object eventObject) {
     AccessEvent event = (AccessEvent) eventObject;
-    return TRIGGERING_STATUS_CODE.compareTo(event.getStatusCode()) <= 0;
+
+    if (TRIGGERING_STATUS_CODE.compareTo(event.getStatusCode()) <= 0) {
+      if (System.currentTimeMillis() >= LAST_TRIGGER_DATE + ONE_DAY) {
+        LAST_TRIGGER_DATE = System.currentTimeMillis();
+        return true;
+      }
+    }
+    return false;
   }
 
   public boolean isStarted() {



More information about the logback-dev mailing list