First what I notice is the same int value of your custom levels (both have 
60000).
But: Why that complicated? Why not only define two separate loggers by name, a 
"SuccessLogger" and a "FailLogger"? The places where one of these loggers are 
called know about the success or the failure (your solution has to set the 
correct level, my solution only fetch the correct logger)
Heri

-----Ursprüngliche Nachricht-----
Von: S.Kannan [mailto:techy_k...@yahoo.co.in] 
Gesendet: Freitag, 6. November 2009 09:14
An: log4j-user@logging.apache.org
Betreff: Using two SMTPAppenders


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
log4j.appender.success_appender.from=nore...@mycomp.int
log4j.appender.success_appender.to=kanna...@mycomp.int
log4j.appender.success_appender.cc=kanna...@mycomp.int
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
log4j.appender.failure_appender.from=nore...@mycomp.int
log4j.appender.failure_appender.to=kan...@mycomp.int 
log4j.appender.failure_appender.cc=skan...@mycomp.int
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: log4j-user-unsubscr...@logging.apache.org
For additional commands, e-mail: log4j-user-h...@logging.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-user-unsubscr...@logging.apache.org
For additional commands, e-mail: log4j-user-h...@logging.apache.org

Reply via email to