- java.lang.Object
-
- ch.qos.logback.core.spi.ContextAwareBase
-
- ch.qos.logback.core.sift.AbstractDiscriminator<ILoggingEvent>
-
- ch.qos.logback.classic.sift.MDCBasedDiscriminator
-
- All Implemented Interfaces:
Discriminator<ILoggingEvent>,ContextAware,LifeCycle
public class MDCBasedDiscriminator extends AbstractDiscriminator<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.
MDC values containing any of the characters
/,\,$,{,},[,],(,),|,?,*,+,%,,,@or the sequence..are rejected, in which case the default value is returned. This prevents path separators, relative path components, variable substitutions such as${file.separator}, regex special characters as well as the anchor character '%' or the ',' and '@' characters from leaking into file names or email addresses.Moreover, the maximum length of an MDC value is limited to 64 characters.
- Author:
- Ceki Gülcü
-
-
Field Summary
-
Fields inherited from class ch.qos.logback.core.sift.AbstractDiscriminator
started
-
Fields inherited from class ch.qos.logback.core.spi.ContextAwareBase
context
-
-
Constructor Summary
Constructors Constructor Description MDCBasedDiscriminator()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description StringgetDefaultValue()StringgetDiscriminatingValue(ILoggingEvent event)Return the value associated with an MDC entry designated by the Key property.StringgetKey()The key or variable name under which the discriminating value should be exported into the host environment.voidsetDefaultValue(String defaultValue)The default MDC value in case the MDC is not set formdcKey.voidsetKey(String key)voidstart()-
Methods inherited from class ch.qos.logback.core.sift.AbstractDiscriminator
isStarted, stop
-
Methods inherited from class ch.qos.logback.core.spi.ContextAwareBase
addError, addError, addInfo, addInfo, addStatus, addWarn, addWarn, getContext, getDeclaredOrigin, getStatusManager, setContext
-
-
-
-
Constructor Detail
-
MDCBasedDiscriminator
public MDCBasedDiscriminator()
-
-
Method Detail
-
start
public void start()
- Specified by:
startin interfaceLifeCycle- Overrides:
startin classAbstractDiscriminator<ILoggingEvent>
-
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.If the MDC value contains any of the characters
/,\,$,{or}, or the sequence.., then the value assigned to the DefaultValue property is returned.- Returns:
-
getKey
public String getKey()
Description copied from interface:DiscriminatorThe key or variable name under which the discriminating value should be exported into the host environment.- Returns:
-
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 formdcKey.For example, if
Keyis 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-
-
-