Class AddLoggingContext
- java.lang.Object
-
- com.adaptris.core.ServiceImp
-
- com.adaptris.core.services.AddLoggingContext
-
- All Implemented Interfaces:
AdaptrisComponent,ComponentLifecycle,ComponentLifecycleExtension,MessageEventGenerator,Service,StateManagedComponent
@ComponentProfile(summary="Add a mapped diagnostic context for logging; useful for filtering", tag="service,logging,debug") public class AddLoggingContext extends ServiceImpAdd a mapped diagnostic context viaMDC.put(String, String).It can be useful to use a mapped diagnostic context to provide additional information into your logfile if the underlying logging system supports it (e.g. logback or log4j2)
As the diagnostic logging context is thread based; bear in mind that you will lose the context if part of the service execution chain contains a something like
PoolingMessageSplitterServiceor similar (i.e. something with an underlying thread pool that acts on the message).In the adapter configuration file this class is aliased as add-logging-context-service which is the preferred alternative to the fully qualified classname when building your configuration.
-
-
Field Summary
-
Fields inherited from class com.adaptris.core.ServiceImp
log
-
-
Constructor Summary
Constructors Constructor Description AddLoggingContext()AddLoggingContext(java.lang.String key, java.lang.String value)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected voidcloseService()voiddoService(AdaptrisMessage msg)Apply the service to the message.java.lang.StringgetKey()java.lang.StringgetValue()protected voidinitService()voidprepare()Prepare for initialisation.voidsetKey(java.lang.String key)Set the key for the mapped diagnostic context.voidsetValue(java.lang.String value)Set the value for the mapped diagnostic context.-
Methods inherited from class com.adaptris.core.ServiceImp
changeState, close, continueOnFailure, createName, createQualifier, getContinueOnFail, getIsTrackingEndpoint, getUniqueId, init, isBranching, isTrackingEndpoint, requestClose, requestInit, requestStart, requestStop, retrieveComponentState, setContinueOnFail, setIsTrackingEndpoint, setUniqueId, start, stop
-
-
-
-
Method Detail
-
doService
public void doService(AdaptrisMessage msg) throws ServiceException
Description copied from interface:ServiceApply the service to the message.
- Parameters:
msg- theAdaptrisMessageto process- Throws:
ServiceException- wrapping any underlyingExceptions
-
initService
protected void initService() throws CoreException- Specified by:
initServicein classServiceImp- Throws:
CoreException
-
closeService
protected void closeService()
- Specified by:
closeServicein classServiceImp
-
prepare
public void prepare() throws CoreExceptionDescription copied from interface:ComponentLifecycleExtensionPrepare for initialisation.- Throws:
CoreException
-
getKey
public java.lang.String getKey()
-
setKey
public void setKey(java.lang.String key)
Set the key for the mapped diagnostic context.- Parameters:
key- the key to set
-
getValue
public java.lang.String getValue()
-
setValue
public void setValue(java.lang.String value)
Set the value for the mapped diagnostic context.Supports metadata resolution via
InterlokMessage.resolve(String); and also the magic value$UNIQUE_ID$which places the unique-id as the value.- Parameters:
value- the value to set
-
-