public class MemoryAppender
extends ch.qos.logback.core.read.CyclicBufferAppender<ch.qos.logback.classic.spi.ILoggingEvent>
A CyclicBufferAppender that has an Appender attached to which events are dumped when requested.
See DiagnosticsLoggerFilter for example usage.
Configuration:
Create a logback configuration like this:
<appender name="console" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</pattern>
</encoder>
</appender>
<appender name="DUMPAPPENDER" class="ch.qos.logback.core.FileAppender">
<file>logs/dump.log</file>
<encoder>
<pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</pattern>
</encoder>
</appender>
<appender name="MEMORYAPPENDER" class="nl.surfnet.coin.shared.log.diagnostics.MemoryAppender" />
<logger name="MEMORYLOGGER">
<appender-ref ref="MEMORYAPPENDER" />
<appender-ref ref="DUMPAPPENDER" />
</logger>
<root level="info">
<appender-ref ref="file"/>
<appender-ref ref="MEMORYAPPENDER" />
</root>
Where MEMORY, DUMPLOGGER and DUMPAPPENDER are predefined tokens that are used as references. So you should leave those intact.
| Modifier and Type | Field and Description |
|---|---|
static String |
DEFAULT_DUMP_APPENDER |
static String |
MDC_DISCRIMINATOR_FIELD |
static String |
MEMORY_LOGGER |
| Constructor and Description |
|---|
MemoryAppender() |
| Modifier and Type | Method and Description |
|---|---|
void |
dump(String discriminator)
Dump all stored events for the given discriminator (looked up in the MDC)
|
void |
dumpExternal(List<ch.qos.logback.classic.spi.ILoggingEvent> events)
Accept an arbitrary list of events and dump them to the dump appender.
|
List<ch.qos.logback.classic.spi.ILoggingEvent> |
getBuffer(String discriminator)
Get the events for the given discriminator from the buffer
|
protected ch.qos.logback.core.Appender<ch.qos.logback.classic.spi.ILoggingEvent> |
getDumpAppender() |
void |
setDumpAppender(String dumpAppenderName)
Appender to use for eventual logging when requested.
|
append, get, getLength, getMaxSize, setMaxSize, start, stopaddFilter, clearAllFilters, doAppend, getCopyOfAttachedFiltersList, getFilterChainDecision, getName, isStarted, setName, toStringaddError, addError, addInfo, addInfo, addStatus, addWarn, addWarn, getContext, getDeclaredOrigin, getStatusManager, setContextpublic static final String MDC_DISCRIMINATOR_FIELD
public static final String MEMORY_LOGGER
public static final String DEFAULT_DUMP_APPENDER
public void setDumpAppender(String dumpAppenderName)
dumpAppenderName - the name of the dumpAppenderprotected ch.qos.logback.core.Appender<ch.qos.logback.classic.spi.ILoggingEvent> getDumpAppender()
public void dump(String discriminator)
discriminator - the discriminator to filter onpublic void dumpExternal(List<ch.qos.logback.classic.spi.ILoggingEvent> events)
events - the events to dumpCopyright © 2009-2013 SURFnet bv, The Netherlands. All Rights Reserved.