I've been logging to a database, and sometimes the database connection would 
drop and I'd send mails instead.

The code grew into a bit of a mess over time, and I just decided to clean that 
up; one of the components that fell out is the FallbackAppender: configured 
with a list of appenders, and if one fails, shut it down and use the next one 
on the list.

Would such a contribution be welcome?

Here's the Javadoc, find an outline of the implementation below that.

--

An appender that delegates to one of a list of configured appenders.
If an appender fails, it will never be used again and the next appender in the 
list is used. 

Typical Usage: 

 <appender name="APPENDER1" class="...">
   ...
 </appender>
 <appender name="APPENDER2" class="...">
   ...
 </appender>
 <appender name="APPENDER3" class="...">
   ...
 </appender>
 <appender name="SOME_APPENDER" 
class="de.hennig_fahrzeugteile.lib.logging.FallbackAppender">
   <appenders>APPENDER1,APPENDER2,APPENDER3</appenders>
 </appender>
 
If all appenders fail, stderr is used as an appender of last resort.
If you need specific formatting or encoding on the appender, finish the list 
off with a stderr appender to your liking. 
This appender does not use any formatters or encoders.

--

The code isn't ready yet, what I have looks up all appenders in the context, 
puts them into a list, and iterates over the list as appenders fail.
It also reports any problems via addInfo() and addWarn(); I hope that that's 
enough to play nice with logback's normal mode of operation.
Currently it's 136 LoC, including boilerplate.
_______________________________________________
logback-dev mailing list
[email protected]
http://mailman.qos.ch/mailman/listinfo/logback-dev

Reply via email to