ch.qos.logback.ext.spring
Class DelegatingLogbackAppender

java.lang.Object
  extended by ch.qos.logback.core.spi.ContextAwareBase
      extended by ch.qos.logback.core.UnsynchronizedAppenderBase<ch.qos.logback.classic.spi.ILoggingEvent>
          extended by ch.qos.logback.ext.spring.DelegatingLogbackAppender
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 DelegatingLogbackAppender
extends ch.qos.logback.core.UnsynchronizedAppenderBase<ch.qos.logback.classic.spi.ILoggingEvent>

A Logback Appender implementation which delegates the actual appending to a named bean contained in a Spring ApplicationContext.

This appender is similar in spirit to Spring's DelegatingFilterProxy, which allows servlet filters to be created and wired in the ApplicationContext and then accessed in the filter chain. As with the filter proxy, the delegating appender uses its own name to find the target appender in the context.

Because the logging framework is usually started before the Spring context, this appender supports caching for ILoggingEvents which are received before the ApplicationContext is available. This caching has 3 possible modes:

Caching is on by default, so strong references will be used for all events.

An example of how to use this appender in logback.xml:

 <appender name="appenderBeanName" class="ch.qos.logback.ext.spring.DelegatingLogbackAppender"/>
 

Or, if specifying a different cache mode, e.g.:

 <appender name="appenderBeanName" class="ch.qos.logback.ext.spring.DelegatingLogbackAppender">
     <cacheMode>soft</cacheMode>
 </appender>
 
Using this appender requires that the ApplicationContextHolder be included in the ApplicationContext.

Since:
0.1
Author:
Bryan Turner

Field Summary
 
Fields inherited from class ch.qos.logback.core.UnsynchronizedAppenderBase
name, started
 
Fields inherited from class ch.qos.logback.core.spi.ContextAwareBase
context
 
Constructor Summary
DelegatingLogbackAppender()
           
 
Method Summary
protected  void append(ch.qos.logback.classic.spi.ILoggingEvent event)
           
 String getBeanName()
           
 void setBeanName(String beanName)
           
 void setCacheMode(String mode)
           
 void start()
           
 void stop()
           
 
Methods inherited from class ch.qos.logback.core.UnsynchronizedAppenderBase
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
 

Constructor Detail

DelegatingLogbackAppender

public DelegatingLogbackAppender()
Method Detail

setCacheMode

public void setCacheMode(String mode)

start

public void start()
Specified by:
start in interface ch.qos.logback.core.spi.LifeCycle
Overrides:
start in class ch.qos.logback.core.UnsynchronizedAppenderBase<ch.qos.logback.classic.spi.ILoggingEvent>

stop

public void stop()
Specified by:
stop in interface ch.qos.logback.core.spi.LifeCycle
Overrides:
stop in class ch.qos.logback.core.UnsynchronizedAppenderBase<ch.qos.logback.classic.spi.ILoggingEvent>

append

protected void append(ch.qos.logback.classic.spi.ILoggingEvent event)
Specified by:
append in class ch.qos.logback.core.UnsynchronizedAppenderBase<ch.qos.logback.classic.spi.ILoggingEvent>

getBeanName

public String getBeanName()

setBeanName

public void setBeanName(String beanName)


Copyright © 2012-2013. All Rights Reserved.