org.jcoderz.commons
Class LogThreadContext

java.lang.Object
  extended by org.jcoderz.commons.LogThreadContext

public final class LogThreadContext
extends Object

This class holds logging context information that is bound to the current thread.

The values of the map should be strictly Strings. This is to avoid misuse of the map as thread local cache and to avoid storing large object graphs in the context.

Author:
Andreas Mandel

Method Summary
static Map get()
          Returns the underlying map that is used to store context parameters of the current thread.
static String get(String key)
          Returns the value of the selected context parameter, or null if the selected parameter is not set.
static String put(String key, String value)
          Add a value identified by the given key to the thread context.
static String remove(String key)
          Removes the value that is currently stored for the given key.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

put

public static String put(String key,
                         String value)
Add a value identified by the given key to the thread context.

The adder of the value is responsible that the value is removed if the context is left. There can only be one value set for a given key.

Parameters:
key - the identifier of the value to be set.
value - the value to be stored in the context.
Returns:
the String representation of the previous value stored for this key, or null if no such value was stored.

get

public static String get(String key)
Returns the value of the selected context parameter, or null if the selected parameter is not set.

Parameters:
key - the identifier of the value to be retrieved.
Returns:
the value of the selected context parameter, or null if the selected parameter is not set.

remove

public static String remove(String key)
Removes the value that is currently stored for the given key.

Parameters:
key - the identifier of the value to be removed.
Returns:
the value of the selected context parameter, or null if the selected parameter is not set.

get

public static Map get()
Returns the underlying map that is used to store context parameters of the current thread. Changes on the returned Map will also change the stored logging context.

Returns:
the underlying map that is used to store context parameters of the current thread.


Copyright 2007 The jCoderZ Project.