How to make log4j send emails asynchronously

763 views
Skip to first unread message

Pramode C.E

unread,
Sep 8, 2011, 9:28:28 PM9/8/11
to play-fr...@googlegroups.com
Hi,

I am using log4j (ver 1.2.16) to send ERROR logs to a gmail id ... the problem is that whenever there is an error, processing
gets slowed down (which is I guess because the logger tries to contact the SMTP server and everything is blocked until SMTP
processing is complete). There seems to be some kind of "AsyncAppender" feature to log4j, but I don't see any documentation
as to how this can be used from log4j.properties. Has somebody encountered this issue before? If so, it would be great to know how
you got this fixed!

Regards,
Pramode





Drew Hamlett

unread,
Sep 9, 2011, 10:07:32 AM9/9/11
to play-framework
You need to send emails in a job. http://www.playframework.org/documentation/1.2.3/jobs

You basically just create an instance of the job class and tell it to
run immediately using the now() method.

Damien Gouyette

unread,
Sep 9, 2011, 11:14:11 AM9/9/11
to play-framework
Did you look at this page :

http://marc.info/?l=log4j-user&m=107720852123231

An async appender references the smtp appender, so it sends email
asynchronously

You can also use BufferSize to batch send email :

http://logging.apache.org/log4j/1.2/apidocs/org/apache/log4j/net/SMTPAppender.html

Regards Damien

Pramode C.E

unread,
Sep 9, 2011, 12:34:09 PM9/9/11
to play-fr...@googlegroups.com
On Fri, Sep 9, 2011 at 8:44 PM, Damien Gouyette <damien....@gmail.com> wrote:
Did you look at this page :

http://marc.info/?l=log4j-user&m=107720852123231

An async appender references the smtp appender, so it sends email
asynchronously

Thanks for the link!

In the link above, XML files are being used for configuring log4j; I am trying to find out if there is a way to do this using log4j.properties. 
If BufferSize = N, then log4j will keep N logging events in a buffer and send out an email only when the N'th event is received; but  again, once the mail sending process gets started, I think all other activities will get suspended till all the mails are sent ... this will again introduce a delay! The only way to tide over this problem seems to be using the AsyncAppender ...

Thanks and Regards,
Pramode

Pramode C.E

unread,
Sep 9, 2011, 12:37:24 PM9/9/11
to play-fr...@googlegroups.com
On Fri, Sep 9, 2011 at 7:37 PM, Drew Hamlett <drew...@gmail.com> wrote:
You need to send emails in a job.  http://www.playframework.org/documentation/1.2.3/jobs

You basically just create an instance of the job class and tell it to
run immediately using the now() method.


I am trying to find out how to configure the logger, log4j, to send out email asynchronously!

Thanks and Regards,
Pramode

GrailsDeveloper

unread,
Sep 9, 2011, 2:25:13 PM9/9/11
to play-framework
it only works with xml-config. Notice that your xml-config must name
log4j.xml, so that log4j grep it automatically see
https://play.lighthouseapp.com/projects/57987/tickets/1047

Niels

On 9 Sep., 18:37, "Pramode C.E" <m...@pramode.net> wrote:

Pramode C.E

unread,
Sep 9, 2011, 4:11:31 PM9/9/11
to play-fr...@googlegroups.com
On Fri, Sep 9, 2011 at 11:55 PM, GrailsDeveloper <openso...@googlemail.com> wrote:
it only works with xml-config. Notice that your xml-config must name
log4j.xml, so that log4j grep it automatically see
https://play.lighthouseapp.com/projects/57987/tickets/1047


Thanks for the clarification; so it seems I have to use the xml config itself!

regards,
pramode

Reply all
Reply to author
Forward
0 new messages