logging-log4j-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Shapira, Yoav" <Yoav.Shap...@mpi.com>
Subject RE: SMTP log4j question
Date Tue, 18 Nov 2003 13:49:37 GMT

Howdy,
You need to access the SMTPAppender object and call its methods to
dynamically change the properties like the subject line.  

How are you configuring log4j?  If you know the name of the
SMTPAppender, e.g. "EmailAppender" this is pretty easy.  In your class,
you would do something like:

Logger rootLogger = Logger.getRootLogger();
SMTPAppender email = (SMTPAppender)
rootLogger.getAppender("EmailAppender");
email.setSubject("New subject line");
email.setTo("blah@blah.org");
email.activateOptions();

If you don't know the name of the appender, or don't want to hard-code
it, you can still do this.  Use Logger.getAllAppenders() to get all the
appenders, then iterate through them checking for appender instanceof
SMTPAppender.

A couple of notes since you mentioned you're new to this:

1. By default the SMTP appender will send out ERROR and higher messages
only.  If you want it to send INFO or lower, you will need to change its
Threshold.  Alternatively, you can write a custom
TriggeringEventEvaluator for the appender to use.

2. If you have a small number of possible subject lines and to
addresses, consider creating one SMTP appender for each combination.

Yoav Shapira
Millennium ChemInformatics


>-----Original Message-----
>From: Miller,Catherine [mailto:millerca@oclc.org]
>Sent: Tuesday, November 18, 2003 7:07 AM
>To: 'log4j-user@jakarta.apache.org'
>Subject: SMTP log4j question
>
>I'll start by letting everyone one know I am very new to Java (though
I've
>been in IT for 10yrs) and log4j so please excuse if this is a stupid
>question.
>
>I have been able to set up a test application using log4j to send email
to
>myself as a test for sending some logging information. The next step I
need
>to take is to be able to dynamicly change the to address and the
subject on
>the fly based on what information is to be sent. Part of what we email
are
>integration error messages and these are sent based on what system
>encountered an error. Our old setup was to use a MQSeries queue to hold
>lists of who got what email type(s). The old system is also written in
>Object Rexx. Once it was determined who got the message we used Blat to
>send
>a SMTP message from a central mailing application.
>
>If anyone can help it would be greatly appriciated.
>
>Thanks in advance :)
>
>Cat Miller
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: log4j-user-unsubscribe@jakarta.apache.org
>For additional commands, e-mail: log4j-user-help@jakarta.apache.org




This e-mail, including any attachments, is a confidential business communication, and may
contain information that is confidential, proprietary and/or privileged.  This e-mail is intended
only for the individual(s) to whom it is addressed, and may not be saved, copied, printed,
disclosed or used by anyone else.  If you are not the(an) intended recipient, please immediately
delete this e-mail from your computer system and notify the sender.  Thank you.


---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: log4j-user-help@jakarta.apache.org


Mime
View raw message