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

Jason Buberel jason at buberel.org
Wed Jun 20 21:12:00 CEST 2007


Possibly - that is what I was hoping to achieve with hivemodule's Discardable
interface. However, I could just as easily (were the method 'flush' a public
method that would trigger the sending of the email) add something like this
near the end of my application:

Logger EMAIL_LOGGER = LoggerFactory.getLogger("email");
EMAIL_LOGGER.flush();

-jason


Ceki Gulcu-2 wrote:
> 
> 
> 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
> _______________________________________________
> Logback-user mailing list
> Logback-user at qos.ch
> http://qos.ch/mailman/listinfo/logback-user
> 
> 

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




More information about the Logback-user mailing list