Class MdcInjectionFilter
java.lang.Object
org.apache.mina.core.filterchain.IoFilterAdapter
org.apache.mina.filter.util.CommonEventFilter
org.apache.mina.filter.logging.MdcInjectionFilter
- All Implemented Interfaces:
IoFilter
This filter will inject some key IoSession properties into the Mapped Diagnostic Context (MDC)
These properties will be set in the MDC for all logging events that are generated down the call stack, even in code that is not aware of MINA. By default, the following properties will be set for all transports:
- "handlerClass"
- "remoteAddress"
- "localAddress"
session.getTransportMetadata().getAddressType() == InetSocketAddress.class
the following properties will also be set:
- "remoteIp"
- "remotePort"
- "localIp"
- "localPort"
setProperty(IoSession, String, String)
If you only want the MDC to be set for the IoHandler code, it's enough to add
one MdcInjectionFilter at the end of the filter chain.
If you want the MDC to be set for ALL code, you should
add an MdcInjectionFilter to the start of the chain
and add that same MdcInjectionFilter instance after EVERY ExecutorFilter in the chain
Thus it's ok to have one instance of the MdcInjectionFilter and add it multiple times to the chain
but you should avoid adding multiple instances to the chain.-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enumThis enum lists all the possible keys this filter will processNested classes/interfaces inherited from interface IoFilter
IoFilter.NextFilter -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate ThreadLocal<Integer> private static final AttributeKeykey used for storing the context map in the IoSessionprivate EnumSet<MdcInjectionFilter.MdcKey> -
Constructor Summary
ConstructorsConstructorDescriptionCreate a new MdcInjectionFilter instanceUse this constructor when you want to specify which keys to add to the MDC.Use this constructor when you want to specify which keys to add to the MDC You could still add custom keys viasetProperty(IoSession, String, String) -
Method Summary
Modifier and TypeMethodDescriptionprotected voidfillContext(IoSession session, Map<String, String> context) write key properties of the session to the Mapped Diagnostic Context sub-classes could override this method to map more/other attributesprotected voidfilter(IoFilterEvent event) getAndFillContext(IoSession session) getContext(IoSession session) static StringgetProperty(IoSession session, String key) Get the property associated with a given keystatic voidremoveProperty(IoSession session, String key) Remove a property from the context for the given session This property will be removed from the MDC for all subsequent eventsstatic voidsetProperty(IoSession session, String key, String value) Add a property to the context for the given session This property will be added to the MDC for all subsequent eventsMethods inherited from class CommonEventFilter
event, exceptionCaught, filterClose, filterWrite, inputClosed, messageReceived, messageSent, sessionClosed, sessionCreated, sessionIdle, sessionOpenedMethods inherited from class IoFilterAdapter
destroy, init, onPostAdd, onPostRemove, onPreAdd, onPreRemove, toString
-
Field Details
-
CONTEXT_KEY
key used for storing the context map in the IoSession -
callDepth
-
mdcKeys
-
-
Constructor Details
-
MdcInjectionFilter
Use this constructor when you want to specify which keys to add to the MDC. You could still add custom keys viasetProperty(IoSession, String, String)- Parameters:
keys- set of keys that should be added to the MDC- See Also:
-
MdcInjectionFilter
Use this constructor when you want to specify which keys to add to the MDC You could still add custom keys viasetProperty(IoSession, String, String)- Parameters:
keys- list of keys that should be added to the MDC- See Also:
-
MdcInjectionFilter
public MdcInjectionFilter()Create a new MdcInjectionFilter instance
-
-
Method Details
-
filter
- Specified by:
filterin classCommonEventFilter- Throws:
Exception
-
getAndFillContext
-
getContext
-
fillContext
write key properties of the session to the Mapped Diagnostic Context sub-classes could override this method to map more/other attributes- Parameters:
session- the session to mapcontext- key properties will be added to this map
-
getProperty
-
setProperty
Add a property to the context for the given session This property will be added to the MDC for all subsequent events- Parameters:
session- The session for which you want to set a propertykey- The name of the property (should not be null)value- The value of the property
-
removeProperty
Remove a property from the context for the given session This property will be removed from the MDC for all subsequent events- Parameters:
session- The session for which you want to remove a propertykey- The name of the property (should not be null)
-