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

Jason Buberel jason at buberel.org
Wed Jun 20 21:37:57 CEST 2007


Completely makes sense. I'll give that a try later today and will report back
to the list how well it works.

Thanks for the tip!

-jason


Ceki Gulcu wrote:
> 
> 
> Create a custom evaluator which returns true on events of level ERROR *or*
> on 
> events marked with "FLUSH_SMTP".
> 
> Before exiting your application you call:
> 
>    Marker flush = MarkerFactory.getMarker("FLUSH_SMTP");
>    logger.debug(flush, "Application exiting");
> 
> Does it make sense?
> 
> Jason Buberel wrote:
>> 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
>>>
>>>
>> 
> 
> -- 
> 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#a11220730
Sent from the Logback User mailing list archive at Nabble.com.




More information about the Logback-user mailing list