[logback-user] FallBack Appender and error handler

Ceki Gulcu listid at qos.ch
Tue Jul 22 18:10:52 CEST 2008


Hello Jonathan,

Logback uses a slightly different approach for dealing with internal errors. It 
uses a StatusManager. Each appender is attached to a logger but also to a 
LoggerContext. In turn, the LoggerContext has a reference to a StatusManager. 
All this would be meaningless if logback components did not make use of the 
StatusManger. If you look in the code, logback components, including 
JMSQueueAppener, add a status message when they run into an error.

You would need to listen to these status messages and as soon as you receive one 
which indicating errors in your JMSQueueAppender, you would switch to a 
different JMS destination.

How could you set a listener for status messages? You could either create your 
own StatusManager class and set it for the LoggerContext, or alternatively, you 
could add a listener to the existing StatusManager. Unfortunately, at this time, 
StatusManager cannot be changed, nor does StatusManager class accept listeners. 
However, you can expect these limitations to be lifter soon. See also [1, 2].

Does this help?

[1] http://jira.qos.ch/browse/LBCLASSIC-59
[2] http://tinyurl.com/658jgk



Jonathan Dray wrote:
> Hi,
> 
> I previously used log4j with a JMSAppender sending messages to a specific
> ActiveMq Queue.
> I managed to configure a FallBackErrorHandlor with a second JMSAppender in
> case the first JMSAppender was not able to write to the queue.
> The ErrorHandler was also configured to send emails when something went
> wrong.
> 
> I now want to try logback and wonder if there is a way to get errors
> returned by loggers at runtime.
> Plesae consider the following situation :
> 
> **
>  * Hello world!
>  *
>  */
> public class App
> {
>     public static void main( String[] args )
>     {
>             ...
>             ... (some code herer)
>             Logger log = LoggerFactory.getLogger("myLogger");
>             log.debug("App : main");
>             System.out.println( "Normal end of my process" );
>     }
> }
> 
> Let's assume the "myLogger" is configured to use a JMSAppender.
> I want to know if the log.debug call failed and then not to display "Normal
> end of my process."
> 
> 1. Is this possible ?
> 2. How should I handle errors dealing with logback logger ?
> 
> Thank you
> Regards,
> 
> Jonathan Dray
> 
> 
> 
> ------------------------------------------------------------------------
> 
> _______________________________________________
> Logback-user mailing list
> Logback-user at qos.ch
> http://qos.ch/mailman/listinfo/logback-user

-- 
Ceki Gülcü

QOS.ch is looking to hire talented developers located in Switzerland
to work on cutting-edge software projects. If you think you are
qualified, then please contact ceki at qos.ch.


More information about the Logback-user mailing list