Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Log4j SMTP Appender

Tags:

java

log4j

Hi I am a novice and the application I am currently coding for uses struts 1.2 and java. We currently use Log4j for log files but I need to implement SMTP Appender so that our errors are emailed to us.

I've tried everything to get errors to be emailed with no luck. Below is our log4j.properties file.

Any suggestions?

Thanks!

log4j.rootLogger= INFO, stdout, logfile, mail

log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%d %p [%c] - <%m>%n

# Keep three backup files
log4j.appender.logfile.MaxBackupIndex=3
log4j.appender.logfile.layout=org.apache.log4j.PatternLayout
log4j.appender.logfile.layout.ConversionPattern=%d %p [%c] - <%m>%n
log4j.appender.logfile=org.apache.log4j.RollingFileAppender
log4j.appender.logfile.File=C:/LOGS/WIRE.log
log4j.appender.logfile.MaxFileSize=2048KB

#email appender
log4j.appender.mail=org.apache.log4j.net.SMTPAppender
log4j.appender.mail.BufferSize=1
log4j.appender.mail.SMTPHost=smtp.serverhere.com
[email protected]
[email protected]
log4j.appender.mail.Subject=Application Error
log4j.appender.mail.threshold=error
log4j.appender.mail.layout=org.apache.log4j.PatternLayout
log4j.appender.mail.layout.ConversionPattern=%d %p [%c] - <%m>%n


# Hibernates use of the org.apache classes spews out stuff like mad.
log4j.logger.org.apache=INFO

# Springframework is very talkative too.
log4j.logger.org.springframework=INFO

# acegisecurity 
#log4j.logger.org.acegisecurity = INFO

# Quartz trigger checking 
log4j.logger.org.quartz.impl.jdbcjobstore=INFO
#log4j.logger.org.springframework.scheduling.quartz=INFO
like image 923
Brian Avatar asked Mar 30 '11 16:03

Brian


1 Answers

By default, the appender only sends an email when something is logged at the ERROR or FATAL levels. As a side note, it appears that your threshold property may have improper case. I believe:

log4j.appender.mail.threshold=error

should be

log4j.appender.mail.Threshold=error

Edit...

Log4j can be put into debug mode by configuring the log4j.debug configuration property. This might provide some output regarding the SMTP appender.

like image 130
jt. Avatar answered Sep 28 '22 17:09

jt.