nl.surfnet.coin.shared.log.diagnostics
Class MemoryAppender

java.lang.Object
  extended by ch.qos.logback.core.spi.ContextAwareBase
      extended by ch.qos.logback.core.AppenderBase<E>
          extended by ch.qos.logback.core.read.CyclicBufferAppender<ch.qos.logback.classic.spi.ILoggingEvent>
              extended by nl.surfnet.coin.shared.log.diagnostics.MemoryAppender
All Implemented Interfaces:
ch.qos.logback.core.Appender<ch.qos.logback.classic.spi.ILoggingEvent>, ch.qos.logback.core.spi.ContextAware, ch.qos.logback.core.spi.FilterAttachable<ch.qos.logback.classic.spi.ILoggingEvent>, ch.qos.logback.core.spi.LifeCycle

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.


Field Summary
static String DEFAULT_DUMP_APPENDER
           
static String MDC_DISCRIMINATOR_FIELD
           
static String MEMORY_LOGGER
           
 
Fields inherited from class ch.qos.logback.core.AppenderBase
name, started
 
Fields inherited from class ch.qos.logback.core.spi.ContextAwareBase
context
 
Constructor Summary
MemoryAppender()
           
 
Method Summary
 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.
 
Methods inherited from class ch.qos.logback.core.read.CyclicBufferAppender
append, get, getLength, getMaxSize, setMaxSize, start, stop
 
Methods inherited from class ch.qos.logback.core.AppenderBase
addFilter, clearAllFilters, doAppend, getCopyOfAttachedFiltersList, getFilterChainDecision, getName, isStarted, setName, toString
 
Methods inherited from class ch.qos.logback.core.spi.ContextAwareBase
addError, addError, addInfo, addInfo, addStatus, addWarn, addWarn, getContext, getDeclaredOrigin, getStatusManager, setContext
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface ch.qos.logback.core.spi.ContextAware
addError, addError, addInfo, addInfo, addStatus, addWarn, addWarn, getContext, setContext
 

Field Detail

MDC_DISCRIMINATOR_FIELD

public static final String MDC_DISCRIMINATOR_FIELD
See Also:
Constant Field Values

MEMORY_LOGGER

public static final String MEMORY_LOGGER
See Also:
Constant Field Values

DEFAULT_DUMP_APPENDER

public static final String DEFAULT_DUMP_APPENDER
See Also:
Constant Field Values
Constructor Detail

MemoryAppender

public MemoryAppender()
Method Detail

setDumpAppender

public void setDumpAppender(String dumpAppenderName)
Appender to use for eventual logging when requested.

Parameters:
dumpAppenderName - the name of the dumpAppender

getDumpAppender

protected ch.qos.logback.core.Appender<ch.qos.logback.classic.spi.ILoggingEvent> getDumpAppender()

dump

public void dump(String discriminator)
Dump all stored events for the given discriminator (looked up in the MDC)

Parameters:
discriminator - the discriminator to filter on

dumpExternal

public void dumpExternal(List<ch.qos.logback.classic.spi.ILoggingEvent> events)
Accept an arbitrary list of events and dump them to the dump appender. Useful for dumping externally saved events (for example in an http session.

Parameters:
events - the events to dump

getBuffer

public List<ch.qos.logback.classic.spi.ILoggingEvent> getBuffer(String discriminator)
Get the events for the given discriminator from the buffer

Parameters:
discriminator -
Returns:
the list of ILoggingEvents


Copyright © 2009-2013 SURFnet bv, The Netherlands. All Rights Reserved.