ch.qos.logback.ext.spring
Class DelegatingLogbackAppender
java.lang.Object
ch.qos.logback.core.spi.ContextAwareBase
ch.qos.logback.core.UnsynchronizedAppenderBase<ch.qos.logback.classic.spi.ILoggingEvent>
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
ILoggingEvent
s which are received before the ApplicationContext
is available. This caching has
3 possible modes:
- off - Events are discarded until the
ApplicationContext
is available.
- on - Events are cached with strong references until the
ApplicationContext
is available, at
which time they will be forwarded to the delegate appender. In systems which produce substantial amounts of log
events while starting up the ApplicationContext
this mode may result in heavy memory usage.
- soft - Events are wrapped in
SoftReference
s and cached until the ApplicationContext
is available. Memory pressure may cause the garbage collector to collect some or all of the cached events before
the ApplicationContext
is available, so some or all events may be lost. However, in systems with heavy
logging, this mode may result in more efficient memory usage.
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
Fields inherited from class ch.qos.logback.core.UnsynchronizedAppenderBase |
name, started |
Fields inherited from class ch.qos.logback.core.spi.ContextAwareBase |
context |
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 interface ch.qos.logback.core.spi.ContextAware |
addError, addError, addInfo, addInfo, addStatus, addWarn, addWarn, getContext, setContext |
DelegatingLogbackAppender
public DelegatingLogbackAppender()
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 © 2014-2015. All Rights Reserved.