Class RequestContextExportingAppender
- java.lang.Object
-
- ch.qos.logback.core.spi.ContextAwareBase
-
- ch.qos.logback.core.UnsynchronizedAppenderBase<ILoggingEvent>
-
- com.linecorp.armeria.common.logback.RequestContextExportingAppender
-
- All Implemented Interfaces:
Appender<ILoggingEvent>,AppenderAttachable<ILoggingEvent>,ContextAware,FilterAttachable<ILoggingEvent>,LifeCycle
public class RequestContextExportingAppender extends UnsynchronizedAppenderBase<ILoggingEvent> implements AppenderAttachable<ILoggingEvent>
A LogbackAppenderthat exports the properties of the currentRequestContexttoMDC.Read 'Logging contextual information' for more information.
-
-
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
Constructors Constructor Description RequestContextExportingAppender()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddAppender(Appender<ILoggingEvent> newAppender)voidaddAttribute(String alias, AttributeKey<?> attrKey)Adds the specifiedAttributeKeyto the export list.voidaddAttribute(String alias, AttributeKey<?> attrKey, Function<?,String> stringifier)Adds the specifiedAttributeKeyto the export list.voidaddBuiltIn(BuiltInProperty property)Adds the specifiedBuiltInPropertyto the export list.voidaddHttpRequestHeader(CharSequence name)Adds the specified HTTP request header name to the export list.voidaddHttpResponseHeader(CharSequence name)Adds the specified HTTP response header name to the export list.protected voidappend(ILoggingEvent eventObject)booleancontainsAttribute(AttributeKey<?> key)Returnstrueif the specifiedAttributeKeyis in the export list.booleancontainsBuiltIn(BuiltInProperty property)Returnstrueif the specifiedBuiltInPropertyis in the export list.booleancontainsHttpRequestHeader(CharSequence name)Returnstrueif the specified HTTP request header name is in the export list.booleancontainsHttpResponseHeader(CharSequence name)Returnstrueif the specified HTTP response header name is in the export list.voiddetachAndStopAllAppenders()booleandetachAppender(Appender<ILoggingEvent> appender)booleandetachAppender(String name)protected voidexport(Map<String,String> out, com.linecorp.armeria.common.RequestContext ctx, com.linecorp.armeria.common.logging.RequestLog log)Exports the necessary properties toMDC.Appender<ILoggingEvent>getAppender(String name)Map<String,AttributeKey<?>>getAttributes()Returns allAttributeKeys in the export list.Set<BuiltInProperty>getBuiltIns()Returns allBuiltInPropertys in the export list.Set<AsciiString>getHttpRequestHeaders()Returns all HTTP request header names in the export list.Set<AsciiString>getHttpResponseHeaders()Returns all HTTP response header names in the export list.booleanisAttached(Appender<ILoggingEvent> appender)Iterator<Appender<ILoggingEvent>>iteratorForAppenders()voidsetExport(String mdcKey)Adds the property represented by the specified MDC key to the export list.voidsetExports(String mdcKeys)Adds the properties represented by the specified comma-separated MDC keys to the export list.voidstart()voidstop()-
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
-
-
-
-
Method Detail
-
addBuiltIn
public void addBuiltIn(BuiltInProperty property)
Adds the specifiedBuiltInPropertyto the export list.
-
containsBuiltIn
public boolean containsBuiltIn(BuiltInProperty property)
Returnstrueif the specifiedBuiltInPropertyis in the export list.
-
getBuiltIns
public Set<BuiltInProperty> getBuiltIns()
Returns allBuiltInPropertys in the export list.
-
addAttribute
public void addAttribute(String alias, AttributeKey<?> attrKey)
Adds the specifiedAttributeKeyto the export list.- Parameters:
alias- the alias of the attribute to exportattrKey- the key of the attribute to export
-
addAttribute
public void addAttribute(String alias, AttributeKey<?> attrKey, Function<?,String> stringifier)
Adds the specifiedAttributeKeyto the export list.
-
containsAttribute
public boolean containsAttribute(AttributeKey<?> key)
Returnstrueif the specifiedAttributeKeyis in the export list.
-
getAttributes
public Map<String,AttributeKey<?>> getAttributes()
Returns allAttributeKeys in the export list.- Returns:
- the
Mapwhose key is an alias and value is anAttributeKey
-
addHttpRequestHeader
public void addHttpRequestHeader(CharSequence name)
Adds the specified HTTP request header name to the export list.
-
addHttpResponseHeader
public void addHttpResponseHeader(CharSequence name)
Adds the specified HTTP response header name to the export list.
-
containsHttpRequestHeader
public boolean containsHttpRequestHeader(CharSequence name)
Returnstrueif the specified HTTP request header name is in the export list.
-
containsHttpResponseHeader
public boolean containsHttpResponseHeader(CharSequence name)
Returnstrueif the specified HTTP response header name is in the export list.
-
getHttpRequestHeaders
public Set<AsciiString> getHttpRequestHeaders()
Returns all HTTP request header names in the export list.
-
getHttpResponseHeaders
public Set<AsciiString> getHttpResponseHeaders()
Returns all HTTP response header names in the export list.
-
setExport
public void setExport(String mdcKey)
Adds the property represented by the specified MDC key to the export list. Note: this method is meant to be used for XML configuration. Useadd*()methods instead.
-
setExports
public void setExports(String mdcKeys)
Adds the properties represented by the specified comma-separated MDC keys to the export list. Note: this method is meant to be used for XML configuration. Useadd*()methods instead.
-
append
protected void append(ILoggingEvent eventObject)
- Specified by:
appendin classUnsynchronizedAppenderBase<ILoggingEvent>
-
export
protected void export(Map<String,String> out, com.linecorp.armeria.common.RequestContext ctx, com.linecorp.armeria.common.logging.RequestLog log)
Exports the necessary properties toMDC. By default, this method exports all properties added to the export list viaadd*()calls and<export />tags. Override this method to export additional properties.
-
start
public void start()
- Specified by:
startin interfaceLifeCycle- Overrides:
startin classUnsynchronizedAppenderBase<ILoggingEvent>
-
stop
public void stop()
- Specified by:
stopin interfaceLifeCycle- Overrides:
stopin classUnsynchronizedAppenderBase<ILoggingEvent>
-
addAppender
public void addAppender(Appender<ILoggingEvent> newAppender)
- Specified by:
addAppenderin interfaceAppenderAttachable<ILoggingEvent>
-
iteratorForAppenders
public Iterator<Appender<ILoggingEvent>> iteratorForAppenders()
- Specified by:
iteratorForAppendersin interfaceAppenderAttachable<ILoggingEvent>
-
getAppender
public Appender<ILoggingEvent> getAppender(String name)
- Specified by:
getAppenderin interfaceAppenderAttachable<ILoggingEvent>
-
isAttached
public boolean isAttached(Appender<ILoggingEvent> appender)
- Specified by:
isAttachedin interfaceAppenderAttachable<ILoggingEvent>
-
detachAndStopAllAppenders
public void detachAndStopAllAppenders()
- Specified by:
detachAndStopAllAppendersin interfaceAppenderAttachable<ILoggingEvent>
-
detachAppender
public boolean detachAppender(Appender<ILoggingEvent> appender)
- Specified by:
detachAppenderin interfaceAppenderAttachable<ILoggingEvent>
-
detachAppender
public boolean detachAppender(String name)
- Specified by:
detachAppenderin interfaceAppenderAttachable<ILoggingEvent>
-
-