Hi,

I've configured Log4j using the configuration file log4j.xml.  However 
when the web application is deployed I'd like the deployer to be able to 
override some of the settings (specifically from and to address) as easily 
as possible.  To make it easy for them the application itself can be 
configured outside of the war file in a properties file.  I'd like to add 
the from and to settings to this file and then using a 
ServletContextListener programmatically set the from and to fields of the 
SMTPAppender.  Here is my code:

    Log4J.configureServerLogger(event);
    Logger log = Logger.getLogger(Log4JContextListener.class);
    log.debug("****Log4J configured****");
    if (log.getParent().getAppender("SSO-SMTP-ERROR") instanceof 
SMTPAppender) {
        SMTPAppender appender = (SMTPAppender) 
log.getParent().getAppender("SSO-SMTP-ERROR");
        if (appender != null) {
                        log.getParent().removeAppender(appender);
                        SMTPAppender newAppender = this.copy(appender);
                        String from = 
SsoProperties.getString(Property.LOG4JFROM.toString());
                        String to = 
SsoProperties.getString(Property.LOG4JTO.toString());
                        if (!StringUtils.isEmpty(from)) {
                                log.debug("Setting SMTPAppender from: " + 
from);
                                newAppender.setFrom(from);
                        }
                        if (!StringUtils.isEmpty(to)) {
                                log.debug("Setting SMTPAppender to: " + 
to);
                                newAppender.setTo(to);
                        }
                        log.getParent().addAppender(newAppender);
        } else {
                log.info("Unable to find an SMTPAppender named 
SSO-SMTP-ERROR.  Emails will not be sent from Log4J.");
        }
     }

The problem is that the from and to values that are used are those in the 
log4j.xml config file.  When I inspect the code later at runtime I notice 
that the appender appears to have the correct from and to values that I 
set programmatically but still the email is being sent to the wrong 
recipients.

Does anyone know what I might be doing wrong?

Thanks & Regards

Ted

Whilst this email has been checked for all known viruses, recipients should 
undertake their own virus checking as Xansa will not accept any liability 
whatsoever.

This email and any files transmitted with it are confidential and protected by 
client privilege.  It is solely for the use of the intended recipient.
Please delete it and notify the sender if you have received it in
error. Unauthorised use is prohibited.

Any opinions expressed in this email are those of the individual and not
necessarily the organisation.
     Xansa, Registered Office: 420 Thames Valley Park Drive,
     Thames Valley Park, Reading, RG6 1PU, UK.
     Registered in England No.1000954.
     t  +44 (0)8702 416181
     w  www.xansa.com

Reply via email to