com.atlassian.confluence.util.logging
Class LoggingContext

java.lang.Object
  extended by com.atlassian.confluence.util.logging.LoggingContext

public final class LoggingContext
extends Object

Manages contextual information in the Log4J Mapped Diagnostic Context.

Since:
3.5
See Also:
PatternLayoutWithContext, LoggingContextFilter, MDC

Method Summary
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 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, String 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(String referer)
          Sets the 'referer' value in the logging context.
static void setUrl(String url)
          Sets the 'url' value in the logging context.
static void setUserName(String userName)
          Sets the 'userName' value in the logging context.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

setUrl

public static void setUrl(String url)
Sets the 'url' value in the logging context. Does nothing if url is null.


setUserName

public static void setUserName(String userName)
Sets the 'userName' value in the logging context. Sets it to 'anonymous' if userName is null.


getUserName

public static String getUserName()
Returns the currently mapped 'userName' value from the context, or null if none has been set.


setReferer

public static void setReferer(String referer)
Sets the 'referer' value in the logging context. Does nothing if referer is null.


put

public static void put(String key,
                       String value)
Sets the value associated with the key in the logging context, overwriting any existing value.

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.Object)

remove

public static void remove(String... keys)
Removes any value associated with the keys in the logging context.


isEmpty

public static boolean isEmpty()
Returns true if the logging context has been initialised and has data in it, otherwise false.


getContext

public static Map<String,Object> 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 to put(java.lang.String, java.lang.String) needs to be removed by calling remove(java.lang.String...) with the same key.


clearAll

public static void clearAll()
Clears all MDC information on the current thread. Normally used to clear nested MDC information on a new thread.



Copyright © 2003-2011 Atlassian. All Rights Reserved.