6.3 Tracer

The Tracer module defines a set of functions useful to generate trace messages. It is linked with the O_TRACE compiler option. If O_TRACE is defined (with gcc -DO_TRACE for example) all trace messages will be printed. If O_TRACE is not defined, then only messages with level EXCEPT, INFO, LOG, and WARN will be printed. With a GNU compiler there is even an optimization which makes that calls to tprintf with a level different from EXCEPT, INFO, LOG, or WARN, don’t actually generate object code. This results in zero execution penalty for DEBUG and higher level messages. On non-GNU compilers this optimization is not fully possible. A minimum amount of code will be executed. Mainly tests, not the actual printing functions, which keeps the penalty in reasonable limits.

The Tracer module also gives the possibility to trace messages into files. The default is to print trace messages to stdout, or stderr, but messages can be redirected to files.


Synopsis


  #include <lyric/Tracer.hpp>
  
  TLV::LNONE   = 0x00000000,
  TLV::LEXCEPT = 0x00000001,
  TLV::LINFO   = 0x00000002,
  TLV::LLOG    = 0x00000004,
  TLV::LWARN   = 0x00000008,
  TLV::LDEBUG  = 0x00010000,
  TLV::LDINFO  = 0x00020000,
  TLV::LDLOG   = 0x00040000,
  TLV::LTDEBUG = 0x10000000,
  TLV::LTDINFO = 0x20000000,
  TLV::LTDLOG  = 0x40000000,
  TLV::LSTD    = LEXCEPT | LINFO | LLOG | LWARN,
  TLV::LALL    = 0xffffffff,
  TLV::LALLNOT = 0x0fffffff
  
  void tunmask (uint32 val);
  void trdout (const Path& path, const char* mode);
  void trderr (const Path& path, const char* mode);
  void trdlog (const Path& path, const char* mode);
  void tprintf (uint32 level, const char* format, ...);


Description

The strange TLV::L in front of each level has to be understood as Trace LeVeL. It was defined so because DEBUG, or INFO are defined by some compilers, which results in uncompilable code2.

void trdout (const Path& path, const char* mode)
The trdout redirects the out message stream to a file given in path. The mode argument is interpreted in the same way as in the C library fopen call.

void trderr (const Path& path, const char* mode)
The trderr redirects the err message stream to a file given in path. The mode argument is interpreted in the same way as in the C library fopen call.

void trdlog (const Path& path, const char* mode)
The trdlog redirects the log message stream to a file given in path. The mode argument is interpreted in the same way as in the C library fopen call.

void tprintf (uint32 level, const char* format, ...)
The tprintf function is the workhorse of the tracing mechanism. The level argument must be chosen within one of the TLV variables. Else tprintf works like the standard printf function, with a given format, and a given amount of arguments.