Hi All
There seems to be some trouble configuring two Appenders for sending mails.
In our case we have to define two custom levels and send mails when these
two levels are used for logging.
The following is the custom level class(Since we want both the levels to be
equal something more than FATAL)
public class CustomLevel extends Level {
// Defining SUCCESS constants
public static final int SUCCESS_INT = 60000;
public static final String SUCCESS_STRING = "SUCCESS";
public static final Level SUCCESS = new CustomLevel (SUCCESS_INT,
SUCCESS_STRING, 0);
// Defining FAILURE constants
public static final int FAILURE_INT = 60000;
public static final String FAILURE_STRING = "FAILURE";
public static final Level FAILURE = new CustomLevel (FAILURE_INT,
FAILURE_STRING, 0);
public CustomLevel (int intValue, String levelName, int
sysLogEquivalent) {
super(intValue, levelName, sysLogEquivalent);
}
}
As the default level for mail triggering is ERROR i modified the
log.properties file like the below one
log4j.rootLogger=ALL,DEBUG_APPENDER,....,SUCCESS_APPENDER,FAILURE_APPENDER
log4j.appender.SUCCESS_APPENDER=org.abc.util.MyOwnSmtpAppender
log4j.appender.SUCCESS_APPENDER.BufferSize=1
[email protected]
[email protected]
[email protected]
log4j.appender.SUCCESS_APPENDER.Subject=Tour
log4j.appender.SUCCESS_APPENDER.evaluatorClass=org.abc.util.AbcEventEvaluator
log4j.appender.SUCCESS_APPENDER.Threshold=SUCCESS#org.abc.util.CustomLevel
log4j.appender.SUCCESS_APPENDER.SMTPHost=localhost
log4j.appender.SUCCESS_APPENDER.layout=org.apache.log4j.PatternLayout
log4j.appender.SUCCESS_APPENDER.layout.ConversionPattern=%d [%t] %-5p %c -
%m%n
log4j.appender.FAILURE_APPENDER=org.abc.util.MyOwnSmtpAppender
log4j.appender.FAILURE_APPENDER.BufferSize=1
[email protected]
[email protected]
[email protected]
log4j.appender.FAILURE_APPENDER.evaluatorClass=org.abc.util.AbcEventEvaluator
log4j.appender.FAILURE_APPENDER.Threshold=FAILURE#org.abc.util.CustomLevel
log4j.appender.FAILURE_APPENDER.SMTPHost=localhost
log4j.appender.FAILURE_APPENDER.Subject=Log4J Mail Failure
log4j.appender.FAILURE_APPENDER.layout=org.apache.log4j.PatternLayout
log4j.appender.FAILURE_APPENDER.layout.ConversionPattern=%d [%t] %-5p %c -
%m%n
The AbcEventEvaluatorclass is as follows
public class AbcEventEvaluatorimplements TriggeringEventEvaluator {
@Override
public boolean isTriggeringEvent(LoggingEvent event) {
System.out.println("Trigerring event Level:"+event.getLevel());
boolean isTriggered = false;
if (event.getLevel().equals(CustomLevel.SUCCESS)) {
isTriggered = true;
System.out.println("isTriggeringEvent SUCCESS ");
}else if (event.getLevel().equals(CustomLevel.FAILURE)){
isTriggered = true;
System.out.println("isTriggeringEvent FAILURE ");
}
return isTriggered;
}
}
The customized appender is
public class MyOwnSmtpAppender extends SMTPAppender{
@Override
public void setEvaluatorClass(String arg0) {
// TODO Auto-generated method stub
System.out.println("Setting the evaluator class:"+arg0);
super.setEvaluatorClass(arg0);
}
@Override
public String getEvaluatorClass() {
// TODO Auto-generated method stub
return super.getEvaluatorClass();
}
@Override
public void setThreshold(Priority threshold) {
// TODO Auto-generated method stub
System.out.println("Setting the
threshold"+threshold.getSyslogEquivalent());
super.setThreshold(threshold);
}
@Override
public Priority getThreshold() {
// TODO Auto-generated method stub
return super.getThreshold();
}
}
Now the problem is that i get two mails both from the success level and the
failure level when we just log for only success messages.
11/6/09 1:25 PM Tour
11/6/09 1:25 PM Log4J Mail Failure
Please give some suggestions
--
View this message in context:
http://old.nabble.com/Using-two-SMTPAppenders-tp26228079p26228079.html
Sent from the Log4j - Users mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]