Class LoggingContext
java.lang.Object
com.atlassian.confluence.util.logging.LoggingContext
Manages contextual information in the Log4J Mapped Diagnostic Context.
- Since:
- 3.5
- See Also:
-
Field Summary
Fields -
Method Summary
Modifier and TypeMethodDescriptionstatic 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
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 void
executeWithContext
(Map<String, Object> context, Runnable runnable) Execute Runnable with MDC context that is removed once the runnable returns.Returns an immutable copy of the underlying logging context map.static String
Returns the currently mapped 'traceId' value from the context, ornull
if none has been set.static String
Returns the currently mapped 'userName' value from the context, ornull
if none has been set.static boolean
isEmpty()
Returnstrue
if the logging context has been initialised and has data in it, otherwisefalse
.static void
Sets the value associated with the key in the logging context, overwriting any existing value.static void
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
Sets the 'url' value in the logging context.static void
setUserName
(@Nullable String userName) Sets the 'userName' value in the logging context.
-
Field Details
-
TRACE_ID_KEY
- See Also:
-
-
Method Details
-
setUrl
Sets the 'url' value in the logging context. Does nothing if url isnull
. -
setUserName
Sets the 'userName' value in the logging context. Sets it to 'anonymous' if userName isnull
. -
getUserName
Returns the currently mapped 'userName' value from the context, ornull
if none has been set. -
setReferer
Sets the 'referer' value in the logging context. Does nothing if referer isnull
. -
getTraceId
Returns the currently mapped 'traceId' value from the context, ornull
if none has been set. -
put
Sets the value associated with the key in the logging context, overwriting any existing value. The value can either be aString
, object equivalent of a primitive type or aJsonable
.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.- See Also:
-
MDC.put(java.lang.String, java.lang.String)
-
remove
Removes any value associated with the keys in the logging context. -
isEmpty
public static boolean isEmpty()Returnstrue
if the logging context has been initialised and has data in it, otherwisefalse
. -
getContext
Returns an immutable copy of the underlying logging context map. -
clear
public static void clear()Removes all keys from the logging context which are managed by this class. Anything which has been added by a call toput(java.lang.String, java.lang.Object)
needs to be removed by callingremove(java.lang.String...)
with the same key. -
clearUsername
public static void clearUsername() -
clearAll
public static void clearAll()Clears all MDC information on the current thread. Normally used to clear nested MDC information on a new thread. -
executeWithContext
Execute Runnable with MDC context that is removed once the runnable returns.- Parameters:
context
- context to have in MDC while runnable is executed. The values can either be aString
, object equivalent of a primitive type or aJsonable
.runnable
- runnable to execute- Since:
- 5.7
-
executeWithContext
Execute Runnable with supplied key/value in the MDC context that are removed once the runnable returns.- Parameters:
key
- the key for the contextvalue
- the value for the context. The value can either be aString
, object equivalent of a primitive type or aJsonable
.runnable
- runnable to execute- Since:
- 5.9.1
-