log4cpp::NDC Class Reference

#include <NDC.hh>

List of all members.

Classes

struct  DiagnosticContext

Public Types

typedef std::vector
< DiagnosticContext
ContextStack
typedef std::vector
< DiagnosticContext
ContextStack

Public Member Functions

virtual void _clear ()
virtual void _clear ()
virtual ContextStack_cloneStack ()
virtual ContextStack_cloneStack ()
virtual const std::string & _get () const
virtual const std::string & _get () const
virtual size_t _getDepth () const
virtual size_t _getDepth () const
virtual void _inherit (ContextStack *stack)
virtual void _inherit (ContextStack *stack)
virtual std::string _pop ()
virtual std::string _pop ()
virtual void _push (const std::string &message)
virtual void _push (const std::string &message)
virtual void _setMaxDepth (int maxDepth)
virtual void _setMaxDepth (int maxDepth)
 NDC ()
 NDC ()
virtual ~NDC ()
virtual ~NDC ()

Static Public Member Functions

static void clear ()
static void clear ()
static ContextStackcloneStack ()
static ContextStackcloneStack ()
static const std::string & get ()
static const std::string & get ()
static size_t getDepth ()
static size_t getDepth ()
static NDCgetNDC ()
static NDCgetNDC ()
static void inherit (ContextStack *stack)
static void inherit (ContextStack *stack)
static std::string pop ()
static std::string pop ()
static void push (const std::string &message)
static void push (const std::string &message)
static void setMaxDepth (int maxDepth)
static void setMaxDepth (int maxDepth)

Public Attributes

ContextStack _stack

Detailed Description

The NDC class implements nested diagnostic contexts as defined by Neil Harrison in the article "Patterns for Logging Diagnostic Messages" part of the book "<i>Pattern Languages of Program Design 3</i>" edited by Martin et al.

A Nested Diagnostic Context, or NDC in short, is an instrument to distinguish interleaved log output from different sources. Log output is typically interleaved when a server handles multiple clients near-simulatanously.

Interleaved log output can still be meaningful if each log entry from different contexts had a distinctive stamp. This is where NDCs come into play.

Note that NDCs are managed on a per thread basis. NDC operations such as push, pop, clear, getDepth and setMaxDepth affect the NDC of the current thread only. NDCs of other threads remain unaffected.

To build an NDC one uses the push operation. Simply put,

There is no penalty for forgetting to match each push operation with a corresponding pop, except the obvious mismatch between the real application context and the context set in the NDC.

Custom Layouts may include the nested diagnostic context for the current thread in log messages, without any user intervention. Hence, even if a server is serving multiple clients simultaneously, the logs emanating from the same code (belonging to the same category) can still be distinguished because each client request will have a different NDC tag.

Unfortunately, unlike Java, C++ does not have platform independent multithreading support. Therefore, currently log4cpp is not multithread aware, it implicitly assumes only one thread exists, the main process thread.

Definition at line 69 of file include/log4cpp/NDC.hh.


Member Typedef Documentation

Definition at line 81 of file install/include/log4cpp/NDC.hh.

Definition at line 81 of file include/log4cpp/NDC.hh.


Constructor & Destructor Documentation

log4cpp::NDC::NDC (  ) 

Definition at line 74 of file NDC.cpp.

log4cpp::NDC::~NDC (  )  [virtual]

Definition at line 77 of file NDC.cpp.

log4cpp::NDC::NDC (  ) 
virtual log4cpp::NDC::~NDC (  )  [virtual]

Member Function Documentation

virtual void log4cpp::NDC::_clear (  )  [virtual]
void log4cpp::NDC::_clear (  )  [virtual]

Definition at line 80 of file NDC.cpp.

virtual ContextStack* log4cpp::NDC::_cloneStack (  )  [virtual]
NDC::ContextStack * log4cpp::NDC::_cloneStack (  )  [virtual]

Definition at line 84 of file NDC.cpp.

virtual const std::string& log4cpp::NDC::_get (  )  const [virtual]
const std::string & log4cpp::NDC::_get (  )  const [virtual]

Definition at line 88 of file NDC.cpp.

virtual size_t log4cpp::NDC::_getDepth (  )  const [virtual]
size_t log4cpp::NDC::_getDepth (  )  const [virtual]

Definition at line 94 of file NDC.cpp.

virtual void log4cpp::NDC::_inherit ( ContextStack stack  )  [virtual]
void log4cpp::NDC::_inherit ( NDC::ContextStack stack  )  [virtual]

Definition at line 98 of file NDC.cpp.

virtual std::string log4cpp::NDC::_pop (  )  [virtual]
std::string log4cpp::NDC::_pop (  )  [virtual]

Definition at line 102 of file NDC.cpp.

virtual void log4cpp::NDC::_push ( const std::string &  message  )  [virtual]
void log4cpp::NDC::_push ( const std::string &  message  )  [virtual]

Definition at line 108 of file NDC.cpp.

virtual void log4cpp::NDC::_setMaxDepth ( int  maxDepth  )  [virtual]
void log4cpp::NDC::_setMaxDepth ( int  maxDepth  )  [virtual]

Definition at line 116 of file NDC.cpp.

static void log4cpp::NDC::clear (  )  [static]

Clear any nested disgnostic information if any. This method is useful in cases where the same thread can be potentially used over and over in different unrelated contexts.

This method is equivalent to calling the setMaxDepth method with a zero maxDepth argument.

void log4cpp::NDC::clear (  )  [static]

Clear any nested disgnostic information if any. This method is useful in cases where the same thread can be potentially used over and over in different unrelated contexts.

This method is equivalent to calling the setMaxDepth method with a zero maxDepth argument.

Definition at line 31 of file NDC.cpp.

static ContextStack* log4cpp::NDC::cloneStack (  )  [static]

Clone the diagnostic context for the current thread.

Internally a diagnostic context is represented as a stack. A given thread can supply the stack (i.e. diagnostic context) to a child thread so that the child can inherit the parent thread's diagnostic context.

The child thread uses the inherit method to inherit the parent's diagnostic context.

Returns:
Stack A clone of the current thread's diagnostic context.
NDC::ContextStack * log4cpp::NDC::cloneStack (  )  [static]

Clone the diagnostic context for the current thread.

Internally a diagnostic context is represented as a stack. A given thread can supply the stack (i.e. diagnostic context) to a child thread so that the child can inherit the parent thread's diagnostic context.

The child thread uses the inherit method to inherit the parent's diagnostic context.

Returns:
Stack A clone of the current thread's diagnostic context.

Definition at line 35 of file NDC.cpp.

static const std::string& log4cpp::NDC::get (  )  [static]

Get the current diagnostic context string.

Returns:
the context string.
const std::string & log4cpp::NDC::get (  )  [static]

Get the current diagnostic context string.

Returns:
the context string.

Definition at line 39 of file NDC.cpp.

static size_t log4cpp::NDC::getDepth (  )  [static]

Get the current nesting depth of this diagnostic context.

Returns:
the nesting depth
size_t log4cpp::NDC::getDepth (  )  [static]

Get the current nesting depth of this diagnostic context.

Returns:
the nesting depth

Definition at line 43 of file NDC.cpp.

static NDC& log4cpp::NDC::getNDC (  )  [static]

Return the NDC for the current thread.

Returns:
the NDC for the current thread
NDC & log4cpp::NDC::getNDC (  )  [static]

Return the NDC for the current thread.

Returns:
the NDC for the current thread

Definition at line 63 of file NDC.cpp.

static void log4cpp::NDC::inherit ( ContextStack stack  )  [static]
void log4cpp::NDC::inherit ( NDC::ContextStack stack  )  [static]

Definition at line 47 of file NDC.cpp.

static std::string log4cpp::NDC::pop (  )  [static]

Clients should call this method before leaving a diagnostic context.

The returned value is the value that was pushed last. If no context is available, then the empty string "" is returned.

Returns:
String The innermost diagnostic context.
std::string log4cpp::NDC::pop (  )  [static]

Clients should call this method before leaving a diagnostic context.

The returned value is the value that was pushed last. If no context is available, then the empty string "" is returned.

Returns:
String The innermost diagnostic context.

Definition at line 51 of file NDC.cpp.

static void log4cpp::NDC::push ( const std::string &  message  )  [static]

Push new diagnostic context information for the current thread.

The contents of the message parameter is determined solely by the client.

Parameters:
message The new diagnostic context information.
void log4cpp::NDC::push ( const std::string &  message  )  [static]

Push new diagnostic context information for the current thread.

The contents of the message parameter is determined solely by the client.

Parameters:
message The new diagnostic context information.

Definition at line 55 of file NDC.cpp.

static void log4cpp::NDC::setMaxDepth ( int  maxDepth  )  [static]

Set the maximum nesting depth for the current NDC. Curently NDCs do not enforce a maximum depth and consequentially this method has no effect.

Parameters:
maxDepth the maximum nesting depth
void log4cpp::NDC::setMaxDepth ( int  maxDepth  )  [static]

Set the maximum nesting depth for the current NDC. Curently NDCs do not enforce a maximum depth and consequentially this method has no effect.

Parameters:
maxDepth the maximum nesting depth

Definition at line 59 of file NDC.cpp.


Member Data Documentation

Definition at line 171 of file include/log4cpp/NDC.hh.


The documentation for this class was generated from the following files:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines


log4cpp
Author(s): Stephen Roderick
autogenerated on Fri Jan 11 09:51:55 2013