ch.qos.logback.classic.sift
Class MDCBasedDiscriminator

java.lang.Object
  extended by ch.qos.logback.core.spi.ContextAwareBase
      extended by ch.qos.logback.classic.sift.MDCBasedDiscriminator
All Implemented Interfaces:
Discriminator<ILoggingEvent>, ContextAware, LifeCycle

public class MDCBasedDiscriminator
extends ContextAwareBase
implements Discriminator<ILoggingEvent>

MDCBasedDiscriminator essentially returns the value mapped to an MDC key. If the said value is null, then a default value is returned.

Both Key and the DefaultValue are user specified properties.

Author:
Ceki Gülcü

Field Summary
 
Fields inherited from class ch.qos.logback.core.spi.ContextAwareBase
context
 
Constructor Summary
MDCBasedDiscriminator()
           
 
Method Summary
 String getDefaultValue()
           
 String getDiscriminatingValue(ILoggingEvent event)
          Return the value associated with an MDC entry designated by the Key property.
 String getKey()
          The key or variable name under which the discriminating value should be exported into the host environment.
 boolean isStarted()
           
 void setDefaultValue(String defaultValue)
          The default MDC value in case the MDC is not set for mdcKey.
 void setKey(String key)
           
 void start()
           
 void stop()
           
 
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, toString, wait, wait, wait
 

Constructor Detail

MDCBasedDiscriminator

public MDCBasedDiscriminator()
Method Detail

getDiscriminatingValue

public String getDiscriminatingValue(ILoggingEvent event)
Return the value associated with an MDC entry designated by the Key property. If that value is null, then return the value assigned to the DefaultValue property.

Specified by:
getDiscriminatingValue in interface Discriminator<ILoggingEvent>
Returns:

isStarted

public boolean isStarted()
Specified by:
isStarted in interface LifeCycle

start

public void start()
Specified by:
start in interface LifeCycle

stop

public void stop()
Specified by:
stop in interface LifeCycle

getKey

public String getKey()
Description copied from interface: Discriminator
The key or variable name under which the discriminating value should be exported into the host environment.

Specified by:
getKey in interface Discriminator<ILoggingEvent>
Returns:

setKey

public void setKey(String key)

getDefaultValue

public String getDefaultValue()
Returns:
See Also:
setDefaultValue(String)

setDefaultValue

public void setDefaultValue(String defaultValue)
The default MDC value in case the MDC is not set for mdcKey.

For example, if Key is set to the value "someKey", and the MDC is not set for "someKey", then this appender will use the default value, which you can set with the help of this method.

Parameters:
defaultValue -


Copyright © 2005-2013 QOS.ch. All Rights Reserved.