I enabled logging in my application, and I want to send logs error by email (gmail account). I:
log4j.rootLogger= mainlogger, Email, dest log4j.appender.mainlogger=org.apache.log4j.ConsoleAppender log4j.appender.mainlogger.target=System.out log4j.appender.mainlogger.layout=org.apache.log4j.PatternLayout log4j.appender.mainlogger.layout.ConversionPattern=%d{dd MMM yyyy HH:mm:ss,SSS} %p %-4r [%t] %-5p %c %x - %m%n log4j.appender.dest=org.apache.log4j.FileAppender log4j.appender.dest.File=log.log log4j.appender.dest.layout=org.apache.log4j.PatternLayout log4j.appender.dest.layout.ConversionPattern=%d{dd MMM yyyy HH:mm:ss,SSS} %p %-4r [%t] %-5p %c %x - %m%n
Configuring the SMTP appender
log4j.appender.Email=org.apache.log4j.net.SMTPAppender
log4j.appender.Email.BufferSize=512
log4j.appender.Email.Threshold=ERROR
log4j.appender.Email.SMTPHost=smtp.gmail.com
log4j.appender.Email.SMTPUsername=myusername
log4j.appender.Email.SMTPPassword=mypassword
[email protected]
[email protected]
log4j.appender.Email.Subject=Error Report
log4j.appender.Email.layout=org.apache.log4j.PatternLayout
log4j.appender.Email.layout.ConversionPattern=%d [%t] %-5p %c %x - %m%n
There is nothing that happened no email sent and no error shown , and I do not understand why, Please any idea about that topic ???
The SMTP Appender provided by Log4J does not setup the necessary parameters to support GMail by default. It does not issue the STARTTLS command to initiate a SMTP session. You could rectify this by:
Here is a example : (because I tried very hard for a few days,now its works)
the trick is : log4j.appender.gmail.SMTPProtocol=smtps
> log4j.rootLogger= ERROR,gmail
> log4j.appender.gmail=org.apache.log4j.net.SMTPAppender
> log4j.appender.gmail.SMTPProtocol=smtps
> [email protected]
> log4j.appender.gmail.SMTPPassword=Your gmail password
> log4j.appender.gmail.threshold=error
> log4j.appender.gmail.SMTPHost=smtp.gmail.com
> log4j.appender.gmail.SMTPPort=465
> log4j.appender.gmail.smtp.starttls.enable=true
> log4j.appender.gmail.Subject=Logging Message via Gmail
> [email protected]
> [email protected]
> log4j.appender.gmail.layout=org.apache.log4j.PatternLayout
> log4j.appender.gmail.layout.ConversionPattern=%d{MM/dd/yyyy HH:mm:ss}[%M] %-5p %C - %m%n
>log4j.appender.gmail.BufferSize=5
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With