A class to print colored debug messages. More...
#include <dbg.h>
Public Member Functions | |
cDBG (bool flag=false, char const *color="red", std::ostream *fd=&std::cerr) | |
bool | GetFlag (void) const |
void | PDM (char const *fmt,...) SDH__attribute__((format(printf |
void | SetColor (char const *color) |
void | SetFlag (bool flag) |
void | SetOutput (std::ostream *fd) |
~cDBG () | |
Protected Attributes | |
char const * | debug_color |
bool | debug_flag |
std::streamsize | mywidth |
char const * | normal_color |
std::ostream * | output |
A class to print colored debug messages.
If the environment variable "SDH_NO_COLOR" is defined then the messages are printed without coloring (usefull for logging or if your terminal does not support colors.
Example:
#include "sdh/dbg.h" d = cDBG( true ); g = cDBG( true, "green" ); d.PDM( "This message is printed in default color red" ); g << "and this one in a nice green "; g << "of course you can debug print any objects that have a string representation: " << 08 << 15 << true; g << "Messages can be turned of and on, e.g. selected by command line options"; g.SetFlag(false); g << "This messages is not printed";
cDBG::cDBG | ( | bool | flag = false , |
char const * | color = "red" , |
||
std::ostream * | fd = &std::cerr |
||
) | [inline] |
constructor: construct a cDBG object
flag | - the initial state of the flag, if true then messages sent to the object are printed. Default is false. Can be changed with SetFlag() |
color | - the name of the color to use, default is "red". Can be changed with SetColor() |
fd | - the ostream to use for output, default is stderr. Can be changed with SetOutput() |
cDBG::~cDBG | ( | ) | [inline] |
bool cDBG::GetFlag | ( | void | ) | const [inline] |
void cDBG::PDM | ( | char const * | fmt, |
... | |||
) |
Print debug messages of printf like fmt, ... in the color set with SetColor, but only if debug_flag is true.
void cDBG::SetColor | ( | char const * | color | ) | [inline] |
void cDBG::SetFlag | ( | bool | flag | ) | [inline] |
void cDBG::SetOutput | ( | std::ostream * | fd | ) | [inline] |
char const* cDBG::debug_color [protected] |
bool cDBG::debug_flag [protected] |
std::streamsize cDBG::mywidth [protected] |
char const* cDBG::normal_color [protected] |
std::ostream* cDBG::output [protected] |