Yate
Public Types | Public Member Functions | Static Public Member Functions | List of all members
Debugger Class Reference

An object that logs messages on creation and destruction. More...

#include <yateclass.h>

Public Types

enum  Formatting {
  None = 0 , Relative , Absolute , Textual ,
  TextLocal , TextSep , TextLSep
}
 

Public Member Functions

 Debugger (const char *name, const char *format=0,...)
 
 Debugger (int level, const char *name, const char *format=0,...)
 
 ~Debugger ()
 

Static Public Member Functions

static void setOutput (void(*outFunc)(const char *, int)=0)
 
static void setIntOut (void(*outFunc)(const char *, int)=0)
 
static void setAlarmHook (void(*alarmFunc)(const char *, int, const char *, const char *)=0)
 
static void setRelayHook (void(*relayFunc)(int, const char *, const char *, const char *)=0)
 
static void enableOutput (bool enable=true, bool colorize=false)
 
static uint32_t getStartTimeSec ()
 
static Formatting getFormatting ()
 
static void setFormatting (Formatting format, uint32_t startTimeSec=0)
 
static unsigned int formatTime (char *buf, Formatting format=getFormatting())
 
static void relayOutput (int level, char *buffer, const char *component=0, const char *info=0)
 

Detailed Description

An object that logs messages on creation and destruction.

This class is used as an automatic variable that logs messages on creation and destruction (when the instruction block is left or function returns). IMPORTANT: the name is not copied so it should best be static.

Member Enumeration Documentation

◆ Formatting

enum Formatting

Timestamp formatting

Constructor & Destructor Documentation

◆ Debugger() [1/2]

Debugger ( const char *  name,
const char *  format = 0,
  ... 
)
explicit

The constructor prints the method entry message and indents.

Parameters
nameName of the function or block entered, must be static
formatprintf() style format string

◆ Debugger() [2/2]

Debugger ( int  level,
const char *  name,
const char *  format = 0,
  ... 
)

The constructor prints the method entry message and indents.

Parameters
levelThe level of the message
nameName of the function or block entered, must be static
formatprintf() style format string

◆ ~Debugger()

~Debugger ( )

The destructor prints the method leave message and deindents.

Member Function Documentation

◆ enableOutput()

static void enableOutput ( bool  enable = true,
bool  colorize = false 
)
static

Enable or disable the debug output

Parameters
enableSet to true to globally enable output
colorizeEnable ANSI colorization of output

◆ formatTime()

static unsigned int formatTime ( char *  buf,
Formatting  format = getFormatting() 
)
static

Fill a buffer with a current timestamp prefix

Parameters
bufBuffer to fill, must be at least 28 characters long
formatDesired timestamp formatting
Returns
Length of the prefix written in buffer excluding final NUL

◆ getFormatting()

static Formatting getFormatting ( )
static

Retrieve the format of timestamps

Returns
The current formatting type for timestamps

◆ getStartTimeSec()

static uint32_t getStartTimeSec ( )
static

Retrieve the start timestamp

Returns
Start timestamp value in seconds

◆ relayOutput()

static void relayOutput ( int  level,
char *  buffer,
const char *  component = 0,
const char *  info = 0 
)
static

Processes a preformatted string as Output, Debug or Alarm. This method is intended to relay messages from other processes, DO NOT USE!

Parameters
levelThe level of the debug or alarm, negative for an output
bufferPreformatted text buffer, MUST HAVE SPACE for at least strlen + 2
componentComponent that emits the alarm if applicable
infoExtra alarm information if applicable

◆ setAlarmHook()

static void setAlarmHook ( void(*)(const char *, int, const char *, const char *)  alarmFunc = 0)
static

Set the alarm hook callback

Parameters
alarmFuncPointer to the alarm callback function, NULL to disable

◆ setFormatting()

static void setFormatting ( Formatting  format,
uint32_t  startTimeSec = 0 
)
static

Set the format of timestamps on output messages and set the time start reference

Parameters
formatDesired timestamp formatting
startTimeSecOptional start timestamp (in seconds)

◆ setIntOut()

static void setIntOut ( void(*)(const char *, int)  outFunc = 0)
static

Set the interactive output callback

Parameters
outFuncPointer to the output function, NULL to disable

◆ setOutput()

static void setOutput ( void(*)(const char *, int)  outFunc = 0)
static

Set the output callback

Parameters
outFuncPointer to the output function, NULL to use stderr

◆ setRelayHook()

static void setRelayHook ( void(*)(int, const char *, const char *, const char *)  relayFunc = 0)
static

Set the relay hook callback that will process all Output, Debug and Alarm

Parameters
relayFuncPointer to the relay callback function, NULL to disable

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