libcwdversion 2.0.0
The C++ Debugging Support Library
Loading...
Searching...
No Matches
Format Of The Debug Output

Customizing the layout of debug output (margins, markers, indentation). More...

Classes

class  libcwd::DebugString
 A string class used for the debug output margin and marker. More...

Functions

DebugStringlibcwd::DebugObject::color_on ()
 Colorization code.
DebugStringlibcwd::DebugObject::color_off ()
 Turn colorization off.
DebugStringlibcwd::DebugObject::margin ()
 The margin.
DebugStringlibcwd::DebugObject::marker ()
 The marker.
void libcwd::DebugObject::push_margin ()
 Push the current margin on a stack.
void libcwd::DebugObject::pop_margin ()
 Pop margin from the stack.
void libcwd::DebugObject::push_marker ()
 Push the current marker on a stack.
void libcwd::DebugObject::pop_marker ()
 Pop marker from the stack.
void libcwd::DebugObject::set_indent (unsigned short indentation)
 Set number of spaces to indent.
void libcwd::DebugObject::inc_indent (unsigned short indentation)
 Increment number of spaces to indent.
void libcwd::DebugObject::dec_indent (unsigned short indentation)
 Decrement number of spaces to indent.
unsigned short libcwd::DebugObject::get_indent () const
 Get the current indentation.

Detailed Description

All debug output is written in the following format:

<margin> <label> <marker> <indentation> <data> <suffix>

The <margin> field can for instance be used to print the ID of the process or thread (useful when writing debug messages from more than one process or thread to the same ostream device).

The <marker> field can be used to identify regions (for example with a vertical line) depending on the current context.

The <indentation> field consists of spaces and is intended to make debug output better readable by grouping lines of debug output as an easier alternative than using the marker field for that purpose.

The <label> field exists of the channel label (as passed to the constructor of a Channel) padded by spaces to make this field constant in width (it is padded to the length of the longest existing channel label), followed by the marker, which is by default a colon plus a final space; for example "NOTICE:".

The <data> field represents the second field of the Dout macro, written to the debug ostream with the operator<< inserters.

Finally, the <suffix> field is by default a new-line, optionally followed by a flush. The debug control flag error_cf however, causes an error message to be inserted first. The suffix field could become for example ": EAGAIN (Try again)\\n".

See also
control-flags

Example:

Debug(libcw_do.margin().assign("*** ", 4));
Debug(libcw_do.marker().assign(": | ", 4));
Dout(dc::notice, "This line is not indented");
Dout(dc::notice, "This line is indented 4 spaces");
Dout(dc::notice, "This line is indented 6 spaces");
void assign(char const *str, size_t len)
Assign str with size len to the string.
Definition DebugString.inl.h:29
#define Dout(cntrl,...)
Macro for writing debug output.
Definition debug.h:97
#define Debug(...)
Encapsulation macro for general debugging code.
Definition debug.h:69
void inc_indent(unsigned short indentation)
Increment number of spaces to indent.
Definition DebugObject.inl.h:84
DebugString & marker()
The marker.
Definition DebugObject.inl.h:60
DebugString & margin()
The margin.
Definition DebugObject.inl.h:48
void set_indent(unsigned short indentation)
Set number of spaces to indent.
Definition DebugObject.inl.h:75
DebugObject libcw_do
The default debug object.
Definition debug.cxx:222

Outputs

*** NOTICE  : | This line is not indented
*** NOTICE  : |     This line is indented 4 spaces
*** NOTICE  : |       This line is indented 6 spaces

Function Documentation

◆ color_off()

DebugString & libcwd::DebugObject::color_off ( )
inline

This is printed before the newline. The color_off string can be manipulated directly using the methods of class DebugString.

References color_off().

Referenced by color_off().

◆ color_on()

DebugString & libcwd::DebugObject::color_on ( )
inline

This is printed before the margin. The color_on string can be manipulated directly using the methods of class DebugString.

References color_on().

Referenced by color_on().

◆ margin()

DebugString & libcwd::DebugObject::margin ( )
inline

This is printed before the label. The margin can be manipulated directly using the methods of class DebugString.

See also
push_margin()
pop_margin()

References margin().

Referenced by margin(), pop_margin(), and push_margin().

◆ marker()

DebugString & libcwd::DebugObject::marker ( )
inline

This is printed after the label. The marker can be manipulated directly using the methods of class DebugString.

See also
push_marker()
pop_marker()

References marker().

Referenced by marker(), pop_marker(), and push_marker().