Apache Log4cxx: log4cxx::MDC Class Reference (original) (raw)
A Mapped Diagnostic Context, or MDC in short, is an instrument for distinguishing interleaved log output from different sources. More...
#include <[mdc.h](mdc%5F8h%5Fsource.html)>
| Public Member Functions |
|---|
| Static Public Member Functions | |
|---|---|
| static void | put (const std::string &key, const std::string &value) |
| Set the key context in the current thread's context map to value. | |
| static void | putLS (const LogString &key, const LogString &value) |
| Set the key context in the current thread's context map to value. | |
| static std::string | get (const std::string &key) |
| Get the context identified by the key parameter. | |
| static bool | get (const LogString &key, LogString &dest) |
| Gets the context identified by the key parameter. | |
| static std::string | remove (const std::string &key) |
| Remove the the context identified by the key parameter. | |
| static void | put (const std::wstring &key, const std::wstring &value) |
| Set the key context in the current thread's context map to value. | |
| static std::wstring | get (const std::wstring &key) |
| Get the context identified by the key parameter. | |
| static std::wstring | remove (const std::wstring &key) |
| Remove the the context identified by the key parameter. | |
| static void | put (const std::basic_string< UniChar > &key, const std::basic_string< UniChar > &value) |
| Set the key context in the current thread's context map to value. | |
| static std::basic_string< UniChar > | get (const std::basic_string< UniChar > &key) |
| Get the context identified by the key parameter. | |
| static std::basic_string< UniChar > | remove (const std::basic_string< UniChar > &key) |
| Remove the the context identified by the key parameter. | |
| static void | put (const CFStringRef &key, const CFStringRef &value) |
| Set the key context in the current thread's context map to value. | |
| static CFStringRef | get (const CFStringRef &key) |
| Get the context identified by the key parameter. | |
| static CFStringRef | remove (const CFStringRef &key) |
| Remove the the context identified by the key parameter. | |
| static bool | remove (const LogString &key, LogString &prevValue) |
| Remove the the context identified by the key parameter. | |
| static void | clear () |
| Clear all entries in the MDC. | |
A Mapped Diagnostic Context, or MDC in short, is an instrument for distinguishing interleaved log output from different sources.
Log output is typically interleaved when a server handles multiple clients near-simultaneously.
MDC provides a constructor and destructor which simply call the put and remove methods, allowing for automatic cleanup when the current scope ends.
MDC operations such as put, remove and clear affect only logging events emitted in the calling thread. The contexts of other threads are not changed. That is, contexts are managed on a per thread basis.
The MDC class is similar to the [NDC](classlog4cxx%5F1%5F1NDC.html) class except that it is based on a map instead of a stack.
◆ Map
String to string stl map.
◆ MDC() [1/4]
| log4cxx::MDC::MDC | ( | const std::string & | key, |
|---|---|---|---|
| const std::string & | value | ||
| ) |
Places a key/value pair in the MDC for the current thread which will be removed during the corresponding destructor.
Both construction and destruction are expected to be on the same thread.
Parameters
| key | context identifier |
|---|---|
| value | a string that distinguishes this context. |
◆ MDC() [2/4]
| log4cxx::MDC::MDC | ( | const std::wstring & | key, |
|---|---|---|---|
| const std::wstring & | value | ||
| ) |
Places a key/value pair in the MDC for the current thread which will be removed during the corresponding destructor.
Both construction and destruction are expected to be on the same thread.
Parameters
| key | context identifier |
|---|---|
| value | a string that distinguishes this context. |
◆ MDC() [3/4]
| log4cxx::MDC::MDC | ( | const std::basic_string< UniChar > & | key, |
|---|---|---|---|
| const std::basic_string< UniChar > & | value | ||
| ) |
Places a key/value pair in the MDC for the current thread which will be removed during the corresponding destructor.
Both construction and destruction are expected to be on the same thread.
Parameters
| key | context identifier |
|---|---|
| value | a string that distinguishes this context. |
◆ MDC() [4/4]
Places a key/value pair in the MDC for the current thread which will be removed during the corresponding destructor.
Both construction and destruction are expected to be on the same thread.
Parameters
| key | context identifier |
|---|---|
| value | a string that distinguishes this context. |
◆ clear()
| static void log4cxx::MDC::clear ( ) | static |
|---|
Clear all entries in the MDC.
A thread that adds to the diagnostic context by calling put should call this method before exiting to prevent unbounded memory usage.
◆ get() [1/5]
Get the context identified by the key parameter.
This method has no side effects.
Parameters
Returns
value for key, empty if not set.
◆ get() [2/5]
Gets the context identified by the key parameter.
Parameters
| key | context key. |
|---|---|
| dest | destination to which value is appended. |
Returns
true if key has associated value.
◆ get() [3/5]
| static std::basic_string< UniChar > log4cxx::MDC::get ( const std::basic_string< UniChar > & key) | static |
|---|
Get the context identified by the key parameter.
This method has no side effects.
Parameters
Returns
value for key, empty if not set.
◆ get() [4/5]
| static std::string log4cxx::MDC::get ( const std::string & key) | static |
|---|
Get the context identified by the key parameter.
This method has no side effects.
Parameters
Returns
value for key, empty if not set.
◆ get() [5/5]
| static std::wstring log4cxx::MDC::get ( const std::wstring & key) | static |
|---|
Get the context identified by the key parameter.
This method has no side effects.
Parameters
Returns
value for key, empty if not set.
◆ put() [1/4]
Set the key context in the current thread's context map to value.
If the current thread does not have a context map it is created as a side effect.
Parameters
| key | context identifier |
|---|---|
| value | a string that distinguishes this context. |
◆ put() [2/4]
| static void log4cxx::MDC::put ( const std::basic_string< UniChar > & key, const std::basic_string< UniChar > & value ) | static |
|---|
Set the key context in the current thread's context map to value.
If the current thread does not have a context map it is created as a side effect.
Parameters
| key | context identifier |
|---|---|
| value | the value. |
◆ put() [3/4]
| static void log4cxx::MDC::put ( const std::string & key, const std::string & value ) | static |
|---|
Set the key context in the current thread's context map to value.
If the current thread does not have a context map it is created as a side effect.
Parameters
| key | context identifier |
|---|---|
| value | a string that distinguishes this context. |
◆ put() [4/4]
| static void log4cxx::MDC::put ( const std::wstring & key, const std::wstring & value ) | static |
|---|
Set the key context in the current thread's context map to value.
If the current thread does not have a context map it is created as a side effect.
Parameters
| key | context identifier |
|---|---|
| value | a string that distinguishes this context. |
◆ putLS()
Set the key context in the current thread's context map to value.
If the current thread does not have a context map it is created as a side effect.
◆ remove() [1/5]
Remove the the context identified by the key parameter.
Parameters
Returns
value if key had been set, empty if not.
◆ remove() [2/5]
Remove the the context identified by the key parameter.
Parameters
| key | context identifier. |
|---|---|
| prevValue | buffer to which previous value is appended. |
Returns
true if key existed in MDC.
◆ remove() [3/5]
| static std::basic_string< UniChar > log4cxx::MDC::remove ( const std::basic_string< UniChar > & key) | static |
|---|
Remove the the context identified by the key parameter.
Parameters
Returns
value if key had been set, empty if not.
◆ remove() [4/5]
| static std::string log4cxx::MDC::remove ( const std::string & key) | static |
|---|
Remove the the context identified by the key parameter.
Parameters
Returns
value if key had been set, empty if not.
◆ remove() [5/5]
| static std::wstring log4cxx::MDC::remove ( const std::wstring & key) | static |
|---|
Remove the the context identified by the key parameter.
Parameters
Returns
value if key had been set, empty if not.
The documentation for this class was generated from the following file: