[logback-user] Dumping a CyclicBuffer
mweeda at 4idc.com
Thu Oct 2 00:15:53 CEST 2008
Objective: Dump a "history" of recent program operations to a log file when
an Exception arises. By logging to a CyclicBufferAppender, a recent history
at a fairly granular level (INFO, or possibly DEBUG) can be maintained
without accumulating massive amounts of data, and with a minimum of
Setting this up to log to the Cyclical Buffer went well. To get the data out
of the CyclicBuffer and log it to a file, a reference to the
CyclicBufferAppender object is needed, and it is not clear how to get one.
It seems like log.getAppender(String name) should return an Appender, but it
doesn't. How can I obtain such a reference?
Also, once a reference is obtained, and an Object is returned from
cyclicBufferAppender.get(i), what class will that object be? I'm hoping it
is a LoggingEvent object, in which case a simple call to the
fileAppender.doAppend method with the event as a parameter will log the
event to a "permanent" log. Again, the code will need to obtain a reference
to the appropriate FileAppender to log it to. (Appropriate might be
hardcoded, or specified in a properties file.)
Most of the configuration is being done in logback.xml. (File is attached.)
Program code, other than wanting to dump the MEMORY appender, is limited to:
static final Logger log = LoggerFactory.getLogger(Main.class);
and various log.X method calls.
As an aside, it would be even better to loop over all Appenders, and check
to see which ones are CyclicBufferAppenders. The code would dump then
contents of all of the CyclicBufferAppenders, or selected ones based on some
Thanks in advance for your insight.
-------------- next part --------------
A non-text attachment was scrubbed...
Size: 2742 bytes
Desc: not available
Url : http://qos.ch/pipermail/logback-user/attachments/20081001/8612a245/attachment.bin
More information about the Logback-user