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

Ceki Gulcu listid at qos.ch
Wed Jun 20 21:08:14 CEST 2007


Hi Jason,

Is there a specific point in your application when you know that it is about to 
be terminated. Put differently, can you call a specific function (to be 
discussed later) just before exiting your app?

Jason Buberel wrote:
> 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
> 
> 
> 

-- 
Ceki Gülcü
Logback: The reliable, generic, fast and flexible logging framework for Java.
http://logback.qos.ch



More information about the Logback-user mailing list