NDC
The NDC means the nested diagnostic context. It is a Map containing data that is attached to a certain thread. This Map is stored as a ThreadLocal. In general this can be used to attach information for every log request.
The NDC can be used be every formatter to include the thread specific information in every message. For example certain user information or client specific can be used this way.
How to use it
There are three static methods that can be used to put data inside the NDC or modify the data.
public static void put(String key,Object obj)
This method will attach data to the NDC defined by the key and the object.
public static Object get(String key)
This method will return the object stored with the defined key
public static void remove(String key)
This method will delete data from the NDC.
There is another method which is used internally to prepare the log message:
public static String getAsString()
This method is used by the DefaultFormatter and the output will be generated like:
[name1=value1,name2=value2,.....]
In order to generate the valueX the toString method of the specific object is called.