RE: SMTP log4j question

2003-11-18 Thread Shapira, Yoav

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([EMAIL PROTECTED]);
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:[EMAIL PROTECTED]
Sent: Tuesday, November 18, 2003 7:07 AM
To: '[EMAIL PROTECTED]'
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: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




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: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



RE: SMTP log4j question

2003-11-18 Thread Miller,Catherine
Here is a snippet of my properties file. I actually set up many files so I
only included the root and SMTP appender. 

# This configuration illustrates filtering by logger name.
log4j.debug=false

log4j.rootLogger=DEBUG, ROOT
log4j.appender.ROOT=org.apache.log4j.FileAppender
log4j.appender.ROOT.layout=org.apache.log4j.PatternLayout
log4j.appender.ROOT.File=D:/data/home/nqt1/logs/rms/test.log
log4j.appender.ROOT.layout.ConversionPattern=[%t] %-5p %c - %m%n

#configuring the SMTP appender
log4j.logger.SMTP=DEBUG, SMTP
log4j.additivity.SMTP=false
log4j.appender.SMTP.EvaluatorClass=org.oclc.cmnappl.SendMail
log4j.appender.SMTP=org.apache.log4j.net.SMTPAppender
log4j.appender.SMTP.SMTPHost=mailhost.oclc.org
[EMAIL PROTECTED]
log4j.appender.SMTP.subject=Testing the appender
[EMAIL PROTECTED]
log4j.appender.SMTP.layout.LocationInfo=false
log4j.appender.SMTP.layout=org.oclc.cmnappl.HTMLCustom
log4j.appender.SMTP.layout.Title=OPOrder Performance Statistics

I tried your sample but got a NullPointerException. Here is what I coded
based on my properties file. Please let me know if I just screw up coding
it.

Logger rootLogger = Logger.getRootLogger();
SMTPAppender SMTPsetup = (SMTPAppender)
rootLogger.getAppender(SMTP);
SMTPsetup.setSubject(New subject line);
SMTPsetup.setTo([EMAIL PROTECTED]);
SMTPsetup.activateOptions();

Thanks for your help :)

Cat

-Original Message-
From: Shapira, Yoav [mailto:[EMAIL PROTECTED]
Sent: Tuesday, November 18, 2003 8:50 AM
To: Log4J Users List
Subject: RE: SMTP log4j question



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([EMAIL PROTECTED]);
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:[EMAIL PROTECTED]
Sent: Tuesday, November 18, 2003 7:07 AM
To: '[EMAIL PROTECTED]'
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: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




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: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



RE: SMTP log4j question

2003-11-18 Thread Shapira, Yoav

Howdy,
Don't use the same name for a logger as you do for an appender: log4j is
fine with it but it's confusing to humans.

In the code I sent you I assumed your SMTP appender is attached to the
root logger.  In the configuration below, it's not, so the SMTPsetup
variable is null.  You can either attach it to the root logger and use
my code, or use
SMTPAppender SMTPsetup = (SMTPAppender)
Logger.getLogger(SMTP).getAppender(SMTP);

Yoav Shapira
Millennium ChemInformatics


-Original Message-
From: Miller,Catherine [mailto:[EMAIL PROTECTED]
Sent: Tuesday, November 18, 2003 9:02 AM
To: 'Log4J Users List'
Subject: RE: SMTP log4j question

Here is a snippet of my properties file. I actually set up many files
so I
only included the root and SMTP appender.

# This configuration illustrates filtering by logger name.
log4j.debug=false

log4j.rootLogger=DEBUG, ROOT
log4j.appender.ROOT=org.apache.log4j.FileAppender
log4j.appender.ROOT.layout=org.apache.log4j.PatternLayout
log4j.appender.ROOT.File=D:/data/home/nqt1/logs/rms/test.log
log4j.appender.ROOT.layout.ConversionPattern=[%t] %-5p %c - %m%n

#configuring the SMTP appender
log4j.logger.SMTP=DEBUG, SMTP
log4j.additivity.SMTP=false
log4j.appender.SMTP.EvaluatorClass=org.oclc.cmnappl.SendMail
log4j.appender.SMTP=org.apache.log4j.net.SMTPAppender
log4j.appender.SMTP.SMTPHost=mailhost.oclc.org
[EMAIL PROTECTED]
log4j.appender.SMTP.subject=Testing the appender
[EMAIL PROTECTED]
log4j.appender.SMTP.layout.LocationInfo=false
log4j.appender.SMTP.layout=org.oclc.cmnappl.HTMLCustom
log4j.appender.SMTP.layout.Title=OPOrder Performance Statistics

I tried your sample but got a NullPointerException. Here is what I
coded
based on my properties file. Please let me know if I just screw up
coding
it.

Logger rootLogger = Logger.getRootLogger();
SMTPAppender SMTPsetup = (SMTPAppender)
rootLogger.getAppender(SMTP);
SMTPsetup.setSubject(New subject line);
SMTPsetup.setTo([EMAIL PROTECTED]);
SMTPsetup.activateOptions();

Thanks for your help :)

Cat

-Original Message-
From: Shapira, Yoav [mailto:[EMAIL PROTECTED]
Sent: Tuesday, November 18, 2003 8:50 AM
To: Log4J Users List
Subject: RE: SMTP log4j question



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([EMAIL PROTECTED]);
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:[EMAIL PROTECTED]
Sent: Tuesday, November 18, 2003 7:07 AM
To: '[EMAIL PROTECTED]'
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: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




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