MDC Class Reference

The MDC class is similar to the NDC class except that it is based on a map instead of a stack. More...

## Public Types

typedef std::map< LogString, LogString > | Map
| String to string stl map. More...

## Public Member Functions

| 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. More...
| ~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. More...
| 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. More...
| MDC (const CFStringRef &key, const CFStringRef &value)
| Places a key/value pair in the MDC for the current thread which will be removed during the corresponding destructor. More...

## Static Public Member Functions

static void | put (const std::string &key, const std::string &value)
| Put a context value (the `o` parameter) as identified with the `key` parameter into the current thread's context map. More...
static void | putLS (const LogString &key, const LogString &value)
| Put a context value (the `o` parameter) as identified with the `key` parameter into the current thread's context map. More...
static std::string | get (const std::string &key)
| Get the context identified by the `key` parameter. More...
static bool | get (const LogString &key, LogString &dest)
| Gets the context identified by the `key` parameter. More...
static std::string | remove (const std::string &key)
| Remove the the context identified by the `key` parameter. More...
static void | put (const std::wstring &key, const std::wstring &value)
| Put a context value (the `o` parameter) as identified with the `key` parameter into the current thread's context map. More...
static std::wstring | get (const std::wstring &key)
| Get the context identified by the `key` parameter. More...
static std::wstring | remove (const std::wstring &key)
| Remove the the context identified by the `key` parameter. More...
static void | put (const std::basic_string< UniChar > &key, const std::basic_string< UniChar > &value)
| Put a context value (the `o` parameter) as identified with the `key` parameter into the current thread's context map. More...
static std::basic_string< UniChar > | get (const std::basic_string< UniChar > &key)
| Get the context identified by the `key` parameter. More...
static std::basic_string< UniChar > | remove (const std::basic_string< UniChar > &key)
| Remove the the context identified by the `key` parameter. More...
static void | put (const CFStringRef &key, const CFStringRef &value)
| Put a context value (the `o` parameter) as identified with the `key` parameter into the current thread's context map. More...
static CFStringRef | get (const CFStringRef &key)
| Get the context identified by the `key` parameter. More...
static CFStringRef | remove (const CFStringRef &key)
| Remove the the context identified by the `key` parameter. More...
static bool | remove (const LogString &key, LogString &prevValue)
| Remove the the context identified by the `key` parameter. More...
static void | clear ()
| Clear all entries in the MDC. More...

## Detailed Description

The MDC class is similar to the NDC class except that it is based on a map instead of a stack.

It provides mapped diagnostic contexts. 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.

## Member Typedef Documentation

## Map

typedef std::map<LogString, LogString> Map

String to string stl map.

## Constructor & Destructor Documentation

## MDC() [1/4]

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 | key
  value | value.

## ~MDC()

~MDC | ( |  | ) |

## MDC() [2/4]

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 | key
  value | value.

## MDC() [3/4]

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 | key
  value | value.

## MDC() [4/4]

MDC | ( | const CFStringRef & | key,
|  | const CFStringRef & | 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 | key
  value | value.

## Member Function Documentation

## clear()

static void clear | ( |  | ) |

static

Clear all entries in the MDC.

## get() [1/5]

static std::string get | ( | const std::string & | key | ) |

static

Get the context identified by the `key` parameter.

This method has no side effects.

Parameters

  key | key.

Returns
  value for key, empty if not set.

## get() [2/5]

static bool get | ( | const LogString & | key,
|  | LogString & | dest
| ) |  |

static

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::wstring get | ( | const std::wstring & | key | ) |

static

Get the context identified by the `key` parameter.

This method has no side effects.

Parameters

  key | key.

Returns
  value for key, empty if not set.

## get() [4/5]

static std::basic_string<UniChar> get | ( | const std::basic_string< UniChar > & | key | ) |

static

Get the context identified by the `key` parameter.

This method has no side effects.

Parameters

  key | key.

Returns
  value for key, empty if not set.

## get() [5/5]

static CFStringRef get | ( | const CFStringRef & | key | ) |

static

Get the context identified by the `key` parameter.

This method has no side effects.

Parameters

  key | key.

Returns
  value for key, empty if not set.

## put() [1/4]

static void put | ( | const std::string & | key,
|  | const std::string & | value
| ) |  |

static

Put a context value (the `o` parameter) as identified with the `key` parameter into the current thread's context map.

If the current thread does not have a context map it is created as a side effect.

Parameters

  key | key
  value | value.

## put() [2/4]

static void put | ( | const std::wstring & | key,
|  | const std::wstring & | value
| ) |  |

static

Put a context value (the `o` parameter) as identified with the `key` parameter into the current thread's context map.

If the current thread does not have a context map it is created as a side effect.

Parameters

  key | key
  value | value.

## put() [3/4]

static void put | ( | const std::basic_string< UniChar > & | key,
|  | const std::basic_string< UniChar > & | value
| ) |  |

static

Put a context value (the `o` parameter) as identified with the `key` parameter into the current thread's context map.

If the current thread does not have a context map it is created as a side effect.

Parameters

  key | key
  value | value.

## put() [4/4]

static void put | ( | const CFStringRef & | key,
|  | const CFStringRef & | value
| ) |  |

static

Put a context value (the `o` parameter) as identified with the `key` parameter into the current thread's context map.

If the current thread does not have a context map it is created as a side effect.

Parameters

  key | key
  value | value.

## putLS()

static void putLS | ( | const LogString & | key,
|  | const LogString & | value
| ) |  |

static

Put a context value (the `o` parameter) as identified with the `key` parameter into the current thread's context map.

If the current thread does not have a context map it is created as a side effect.

## remove() [1/5]

static std::string remove | ( | const std::string & | key | ) |

static

Remove the the context identified by the `key` parameter.

Parameters

  key | key.

Returns
  value if key had been set, empty if not.

## remove() [2/5]

static std::wstring remove | ( | const std::wstring & | key | ) |

static

Remove the the context identified by the `key` parameter.

Parameters

  key | key.

Returns
  value if key had been set, empty if not.

## remove() [3/5]

static std::basic_string<UniChar> remove | ( | const std::basic_string< UniChar > & | key | ) |

static

Remove the the context identified by the `key` parameter.

Parameters

  key | key.

Returns
  value if key had been set, empty if not.

## remove() [4/5]

static CFStringRef remove | ( | const CFStringRef & | key | ) |

static

Remove the the context identified by the `key` parameter.

Parameters

  key | key.

Returns
  value if key had been set, empty if not.

## remove() [5/5]

static bool remove | ( | const LogString & | key,
|  | LogString & | prevValue
| ) |  |

static

Remove the the context identified by the `key` parameter.

Parameters

  key | key.
  prevValue | buffer to which previous value is appended.

Returns
  true if key existed in MDC.

The documentation for this class was generated from the following file:

- mdc.h