@ParametersAreNonnullByDefault public final class LoggingContext extends Object
PatternLayoutWithContext,
LoggingContextFilter,
MDC| Modifier and Type | Method and Description |
|---|---|
static void |
clear()
Removes all keys from the logging context which are managed by this class.
|
static void |
clearAll()
Clears all MDC information on the current thread.
|
static void |
clearUsername() |
static void |
executeWithContext(Map<String,Object> context,
Runnable runnable)
Execute Runnable with MDC context that is removed once the runnable returns.
|
static void |
executeWithContext(String key,
Object value,
Runnable runnable)
Execute Runnable with supplied key/value in the MDC context that are removed once the runnable returns.
|
static Map<String,Object> |
getContext()
Returns an immutable copy of the underlying logging context map.
|
static String |
getUserName()
Returns the currently mapped 'userName' value from the context, or
null if none has been
set. |
static boolean |
isEmpty()
Returns
true if the logging context has been initialised and has data in it, otherwise
false. |
static void |
put(String key,
Object value)
Sets the value associated with the key in the logging context, overwriting any existing
value.
|
static void |
remove(String... keys)
Removes any value associated with the keys in the logging context.
|
static void |
setReferer(@Nullable String referer)
Sets the 'referer' value in the logging context.
|
static void |
setUrl(@Nullable String url)
Sets the 'url' value in the logging context.
|
static void |
setUserName(@Nullable String userName)
Sets the 'userName' value in the logging context.
|
public static void setUrl(@Nullable String url)
null.public static void setUserName(@Nullable String userName)
null.public static String getUserName()
null if none has been
set.public static void setReferer(@Nullable String referer)
null.public static void put(String key, Object value)
String, object equivalent of a primitive type or a
Jsonable.
Code which calls to this method should remove the context information
by calling remove(java.lang.String...) with the same key in a finally block.
MDC.put(java.lang.String, java.lang.Object)public static void remove(String... keys)
public static boolean isEmpty()
true if the logging context has been initialised and has data in it, otherwise
false.public static Map<String,Object> getContext()
public static void clear()
put(java.lang.String, java.lang.Object) needs to be removed by calling remove(java.lang.String...) with the same
key.public static void clearUsername()
public static void clearAll()
public static void executeWithContext(Map<String,Object> context, Runnable runnable)
context - context to have in MDC while runnable is executed. The values can either be
a String, object equivalent of a primitive type or a Jsonable.runnable - runnable to executepublic static void executeWithContext(String key, Object value, Runnable runnable)
key - the key for the contextvalue - the value for the context. The value can either be
a String, object equivalent of a primitive type or a Jsonable.runnable - runnable to executeCopyright © 2003–2022 Atlassian. All rights reserved.