public class MdcInjectionFilter extends CommonEventFilter
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:
session.getTransportMetadata().getAddressType() == InetSocketAddress.class
the following properties will also be set:
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.Modifier and Type | Class and Description |
---|---|
static class |
MdcInjectionFilter.MdcKey
This enum lists all the possible keys this filter will process
|
IoFilter.NextFilter
Constructor and Description |
---|
MdcInjectionFilter()
Create a new MdcInjectionFilter instance
|
MdcInjectionFilter(EnumSet<MdcInjectionFilter.MdcKey> keys)
Use this constructor when you want to specify which keys to add to the MDC.
|
MdcInjectionFilter(MdcInjectionFilter.MdcKey... keys)
Use this constructor when you want to specify which keys to add to the MDC
You could still add custom keys via
setProperty(IoSession, String, String) |
Modifier and Type | Method and Description |
---|---|
protected void |
fillContext(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 attributes
|
protected void |
filter(IoFilterEvent event) |
static String |
getProperty(IoSession session,
String key)
Get the property associated with a given key
|
static void |
removeProperty(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 events
|
static void |
setProperty(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 events
|
event, exceptionCaught, filterClose, filterWrite, inputClosed, messageReceived, messageSent, sessionClosed, sessionCreated, sessionIdle, sessionOpened
destroy, init, onPostAdd, onPostRemove, onPreAdd, onPreRemove, toString
public MdcInjectionFilter(EnumSet<MdcInjectionFilter.MdcKey> keys)
setProperty(IoSession, String, String)
keys
- set of keys that should be added to the MDCsetProperty(org.apache.mina.core.session.IoSession, String, String)
public MdcInjectionFilter(MdcInjectionFilter.MdcKey... keys)
setProperty(IoSession, String, String)
keys
- list of keys that should be added to the MDCsetProperty(org.apache.mina.core.session.IoSession, String, String)
public MdcInjectionFilter()
protected void filter(IoFilterEvent event) throws Exception
filter
in class CommonEventFilter
Exception
protected void fillContext(IoSession session, Map<String,String> context)
session
- the session to mapcontext
- key properties will be added to this mappublic static String getProperty(IoSession session, String key)
session
- The IoSession
key
- The key we are looking atpublic static void setProperty(IoSession session, String key, String value)
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 propertypublic static void removeProperty(IoSession session, String key)
session
- The session for which you want to remove a propertykey
- The name of the property (should not be null)Copyright © 2004–2022 Apache MINA Project. All rights reserved.