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 "Papierman, Paul" <pp...@ert.com> on 2011/02/15 17:33:41 UTC

Custom EvaluatorClass with SMTPAppender when returning true sends PREVIOUS log message

1)      I've created a custom Evaluator class that I wish to use for the SMTPAppender to not send the same emails for errors over a period of time.


2)      I've added it to my log4j.xml configuration:
   <!-- Buffer events and log them asynchronously -->
   <appender name="ASYNC" class="org.apache.log4j.AsyncAppender">
     <errorHandler class="org.jboss.logging.util.OnlyOnceErrorHandler"/>
     <appender-ref ref="FILE"/>
     <appender-ref ref="CONSOLE"/>
     <appender-ref ref="SMTP"/>
   </appender>


   <!-- EMail events to an administrator -->
   <appender name="SMTP" class="org.apache.log4j.net.SMTPAppender">
     <errorHandler class="org.jboss.logging.util.OnlyOnceErrorHandler"/>
     <!-- this is our custom TriggeringEventEvaluator -->
     <param name="EvaluatorClass" value="com.somewhere.log4j.LimitingTriggeringEventEvaluator"/>
     <param name="Threshold" value="ERROR"/>
     <param name="To" value="myemail@somewhere.com<ma...@somewhere.com>"/>
     <param name="From" value="log4j@somewhere.com<ma...@somewhere.com>"/>
     <param name="Subject" value="LOCALHOST NODE1"/>
     <param name="SMTPHost" value="smtp.somewhere.com"/>
     <param name="BufferSize" value="100"/>
     <layout class="org.apache.log4j.PatternLayout">
       <param name="ConversionPattern" value="[%d{ABSOLUTE},%c{1}] %m%n"/>
     </layout>
   </appender>


3)      I know it's working because I log (via STDOUT) and I can see that isTriggeringEvent is returning false (appropriately) when the same message appears within a time interval. (I tried using LogLog but it doesn't seem to work with JBoss - that's another story)



4)      Most times when I log that I'm returning true (from isTriggeringEvent) because the message is a unique one what I receive via email is the Text from a PREVIOUS message.



-        It sounds like the SMTPAppender Buffer is not working the way its supposed to - or there are multiple 'buffers' being created per JVM?

-        Or is the issue the ASYNC aspect of how the messages are being logged?



In any case its definitely not working as expected. When I return true in isTriggeringEvent, I want to send an email for the message referenced in the LoggingEvent that I just evaluated.



Here's what's happening:

1 = boot application, my internal table is empty so all messages are 'new'

2 - log.error(AAA)  -> isTriggeringEvent retrurns true, this results in an email sent with AAA as the contents which is correct

3 - log.error(AAA)  -> isTriggeringEvent retrurns false, this results in no email sent which is correct since AAA has occurred already

4 - log.error(BBB)  -> isTriggeringEvent retrurns true, which is correct since BBB has not been sent yet. But the email that I receive has the message (AAA) which is incorrect. It should have the contents of the evaluated message, BBB



Any help?




________________________________
Notice: This e-mail message, together with any attachments, contains information of eRT that may be confidential, proprietary copyrighted and/or legally privileged, and is intended solely for the use of the individual or entity named on this message. If you are not the intended recipient, and have received this message in error, please immediately return this by e-mail and then delete it.