org.apache.log
Class ContextMap
java.lang.Object
org.apache.log.ContextMap
- Serializable
public final class ContextMap
extends java.lang.Object
implements Serializable
The ContextMap contains non-hierarchical context information
relevant to a particular LogEvent. It may include information
such as;
- user ->fred
- hostname ->helm.realityforge.org
- ipaddress ->1.2.3.4
- interface ->127.0.0.1
- caller ? ?->com.biz.MyCaller.method(MyCaller.java:18)
- source ? ?->1.6.3.2:33
The context is bound to a thread (and inherited by sub-threads) but
it can also be added to by LogTargets.
static void | bind(ContextMap context) - Bind a particular ContextMap to current thread.
|
void | clear() - Empty the context map.
|
Object | get(String key) - Get an entry from the context.
|
Object | get(String key, Object defaultObject) - Get an entry from the context.
|
static ContextMap | getCurrentContext() - Get the Current ContextMap.
|
static ContextMap | getCurrentContext(boolean autocreate) - Get the Current ContextMap.
|
int | getSize() - Get the number of contexts in map.
|
boolean | isReadOnly() - Determine if context is read-only.
|
void | makeReadOnly() - Make the context read-only.
|
void | set(String key, Object value) - Set a value in context
|
ContextMap
public ContextMap()
Default constructor.
ContextMap
public ContextMap(ContextMap parent)
Constructor that sets parent contextMap.
parent
- the parent ContextMap
bind
public static final void bind(ContextMap context)
Bind a particular ContextMap to current thread.
context
- the context map (may be null)
clear
public void clear()
Empty the context map.
get
public Object get(String key)
Get an entry from the context.
- the object in context or null if none with specified key
get
public Object get(String key,
Object defaultObject)
Get an entry from the context.
key
- the key to mapdefaultObject
- a default object to return if key does not exist
getCurrentContext
public static final ContextMap getCurrentContext()
Get the Current ContextMap.
This method returns a ContextMap associated with current thread. If the
thread doesn't have a ContextMap associated with it then a new
ContextMap is created.
getCurrentContext
public static final ContextMap getCurrentContext(boolean autocreate)
Get the Current ContextMap.
This method returns a ContextMap associated with current thread.
If the thread doesn't have a ContextMap associated with it and
autocreate is true then a new ContextMap is created.
autocreate
- true if a ContextMap is to be created if it doesn't exist
getSize
public int getSize()
Get the number of contexts in map.
- the number of contexts in map
isReadOnly
public boolean isReadOnly()
Determine if context is read-only.
- true if Context is read only, false otherwise
makeReadOnly
public void makeReadOnly()
Make the context read-only.
This makes it safe to allow untrusted code reference
to ContextMap.
set
public void set(String key,
Object value)
Set a value in context
key
- the keyvalue
- the value (may be null)