You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@activemq.apache.org by billy <Bi...@bnsflogistics.com> on 2011/09/12 20:18:05 UTC

Log4j SMTPAppender not working within ActiveMQ-Camel

I want to email WARNINGs and above in my log file to myself, but I'm having
trouble getting the Log4j SMTPAppender to work in ActiveMQ.  I created a
small java test program and verified that my Log4j SMTPAppender properties
are correct and that I can send myself an email, but when I copy these
properties the log4j.properties file that ActiveMQ uses, nothing seems to
work.  My test program is using the activation-1.1.jar, log4j-1.2.14.jar and
commons-logging-1.4.jar from ActiveMQ's lib folders. I'm also dropped
javamail 1.4.1's mail.jar into the ActiveMQ lib folder and I'm using it too. 

Has anyone else run into the problem and know how to fix it?

Here's what I have in my log4j.properties file:

log4j.rootLogger=DEBUG, console, logfile, MAIL

# Console appender
log4j.appender.console=org.apache.log4j.ConsoleAppender
log4j.appender.console.layout=org.apache.log4j.PatternLayout
log4j.appender.console.layout.ConversionPattern=%5p | %m%n
log4j.appender.console.threshold=INFO

# File appender
log4j.appender.logfile=org.apache.log4j.RollingFileAppender
log4j.appender.logfile.file=TestLog4jSmtp.log
log4j.appender.logfile.maxFileSize=1024KB
log4j.appender.logfile.maxBackupIndex=5
log4j.appender.logfile.append=true
log4j.appender.logfile.layout=org.apache.log4j.PatternLayout
log4j.appender.logfile.layout.ConversionPattern=%d | %-5p | %m | %c | %t%n

# Mail appender
log4j.appender.MAIL=org.apache.log4j.net.SMTPAppender
log4j.appender.MAIL.BufferSize=10
log4j.appender.MAIL.SMTPHost=smtp2.mycompany.com
log4j.appender.MAIL.From=root@esbp01
log4j.appender.MAIL.to=billy@mycompany.com
log4j.appender.MAIL.Subject=(TEST) ESB Router Alert
log4j.appender.MAIL.layout=org.apache.log4j.PatternLayout
log4j.appender.MAIL.layout.ConversionPattern=%d [%t] %-5p %c %x - %m%n
log4j.appender.MAIL.threshold=WARN


--
View this message in context: http://activemq.2283324.n4.nabble.com/Log4j-SMTPAppender-not-working-within-ActiveMQ-Camel-tp3808210p3808210.html
Sent from the ActiveMQ - User mailing list archive at Nabble.com.

Re: Log4j SMTPAppender not working within ActiveMQ-Camel

Posted by billy <Bi...@bnsflogistics.com>.
My problem was that I didn't realize the SMTPAppender only sends an email
when an ERROR level event occurs.  I set the SMTP threshold to WARN in my
log4j.properties file.  In my Java test file I did the following:
  log.info("info message");
  log.warn("warn message");
  log.error("error message");
I received one email that showed both the warn and error messages and I
incorrectly assumed that it would log warnings only and didn't realize that
the error event was the actual trigger. 

I did some more searching on the internet and found this article 
http://www.manning-sandbox.com/thread.jspa?messageID=114106 SMTPAppender
Usage  and I saw ewalker talking about the evaluationClass.  

I set up my own evaluationClass and now everything works!

--
View this message in context: http://activemq.2283324.n4.nabble.com/Log4j-SMTPAppender-not-working-within-ActiveMQ-Camel-tp3808210p3810103.html
Sent from the ActiveMQ - User mailing list archive at Nabble.com.

Re: Log4j SMTPAppender not working within ActiveMQ-Camel

Posted by oseymen <oz...@tdpg.com>.
Here are some suggestions:

1. Put "log4j.appender.console.threshold=INFO" (in the console appender) in
a new line - in your config it seems to be in the same line as the statement
above it.
2. You have configured SMTP appender for WARN+ only - double check that you
are generating warning messages from ActiveMQ and that you can see those
messages in console.
3. In rootLogger=DEBUG mode, fire up jconsole and go to
org.apache.activemq\<brokername>\Broker\Operations and execute
reloadLog4jProperties(). You should only see "DEBUG: setDebug: JavaMail
version 1.4.4" in the console. If there is a problem with your
configuration, console should print that out for you instead. Make sure
rootLogger is in DEBUG mode and make sure you have MAIL.SMTPDebug=true
before you do this.

Cheers,
Ozan

--
View this message in context: http://activemq.2283324.n4.nabble.com/Log4j-SMTPAppender-not-working-within-ActiveMQ-Camel-tp3808210p3809958.html
Sent from the ActiveMQ - User mailing list archive at Nabble.com.

Re: Log4j SMTPAppender not working within ActiveMQ-Camel

Posted by billy <Bi...@bnsflogistics.com>.
First, I want to thank you for you assistance.  This problem is a little more
involved than I was hoping for.

I set log4j.appender.MAIL.SMTPDebug=true and restarting AMQ per your
suggestion and didn't see any debug message to stdout.  I thought it might
be that ActiveMQ wasn't finding the log4j.properties files, but I changed
root logging level from INFO to DEBUG and the console messages changed
appropriately; therefore, AMQ can see the log4j.properties file.

I wrote a simple java routine using the same SMTPAppender and same library
jar files that AMQ uses.  The java program is on the same machine as AMQ and
it's SMTPAppender works, so I don't understand how it might be a relay
permissions or ports problem.

Any other ideas?

--
View this message in context: http://activemq.2283324.n4.nabble.com/Log4j-SMTPAppender-not-working-within-ActiveMQ-Camel-tp3808210p3809889.html
Sent from the ActiveMQ - User mailing list archive at Nabble.com.

Re: Log4j SMTPAppender not working within ActiveMQ-Camel

Posted by oseymen <oz...@tdpg.com>.
Best way to debug this is to put log4j.appender.MAIL.SMTPDebug=true and
restart AMQ. log4j will start emitting debug messages to stdout and you will
see what is going wrong.

There might be a problem with relay permissions or ports...

Ozan

--
View this message in context: http://activemq.2283324.n4.nabble.com/Log4j-SMTPAppender-not-working-within-ActiveMQ-Camel-tp3808210p3809492.html
Sent from the ActiveMQ - User mailing list archive at Nabble.com.