Log4j SMTPAppender not working within ActiveMQ-Camel

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

Log4j SMTPAppender not working within ActiveMQ-Camel

bbuzzard
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
Reply | Threaded
Open this post in threaded view
|

Re: Log4j SMTPAppender not working within ActiveMQ-Camel

oseymen
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
Reply | Threaded
Open this post in threaded view
|

Re: Log4j SMTPAppender not working within ActiveMQ-Camel

bbuzzard
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?
Reply | Threaded
Open this post in threaded view
|

Re: Log4j SMTPAppender not working within ActiveMQ-Camel

oseymen
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
Reply | Threaded
Open this post in threaded view
|

Re: Log4j SMTPAppender not working within ActiveMQ-Camel

bbuzzard
In reply to this post by bbuzzard
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 SMTPAppender Usage and I saw ewalker talking about the evaluationClass.  

I set up my own evaluationClass and now everything works!