[logback-user] Q: Howto force flush before exiting

Jason Buberel jason at buberel.org
Wed Jun 20 19:19:17 CEST 2007


Here is the behavior I currently observe:

I am using an SMTPAppender to delivery logging messages to my Inbox. By
default, the SMTPAppender implementation that comes with Logback will
trigger the sending of an email (including all accumulated messages) upon
receipt of an ERROR level logging message.

As a result of the default behavior, you can end up in a situation where you
generate 100 INFO level messages to the SMTPAppender and when your
application exits, no email will have been sent. Those 100 INFO-level
logging messages will be discarded.

Here is the behavior I would like to achieve:

I would like to implement an EventEvaluator or TriggerPolicy that would
force the email to be sent at time of exit or termination. I know that
overriding finalize() is not a reliable method of doing this, as there is no
guarantee that the VM will actually call it.

I did try using hivemodule's Discardable interface in a subclass of
SMTPAppender, which I use elsewhere in my application, but ran into problems
with class loaders and the like.

Any suggestions on the best way to achieve this - guaranteed flush/send of
the email message if there are any unsent events in the queue? 

-jason



-- 
View this message in context: http://www.nabble.com/Q%3A-Howto-force-flush-before-exiting-tf3953809.html#a11218153
Sent from the Logback User mailing list archive at Nabble.com.




More information about the Logback-user mailing list