BTK  0.3dev.0
Open-source library to visualize/process biomechanical data
List of all members | Classes | Public Types | Static Public Member Functions
btk::Logger Class Reference

Log mechanism to display debug message, warnings and errors. More...

#include <btkLogger.h>

Classes

class  Stream
 Helper class to store information regarding the output streams used by the class Logger. More...
 

Public Types

enum  VerboseMode { Quiet = 0, MessageOnly = 1, Normal = 2, Detailed = 3 }
 

Static Public Member Functions

static void Debug (const std::string &msg)
 
static void Debug (const std::string &filename, int line, const std::string &msg)
 
static void Error (const std::string &msg)
 
static void Error (const std::string &filename, int line, const std::string &msg)
 
static const std::string & GetDebugAffix ()
 
static Logger::Stream::Pointer GetDebugStream ()
 
static const std::string & GetErrorAffix ()
 
static Logger::Stream::Pointer GetErrorStream ()
 
static const std::string & GetPrefix ()
 
static VerboseMode GetVerboseMode ()
 
static const std::string & GetWarningAffix ()
 
static Logger::Stream::Pointer GetWarningStream ()
 
static void SetDebugAffix (const std::string &str)
 
static void SetDebugStream (std::ostream *output)
 
static void SetDebugStream (Logger::Stream::Pointer stream)
 
static void SetErrorAffix (const std::string &str)
 
static void SetErrorStream (std::ostream *output)
 
static void SetErrorStream (Logger::Stream::Pointer stream)
 
static void SetPrefix (const std::string &str)
 
static void SetVerboseMode (VerboseMode mode)
 
static void SetWarningAffix (const std::string &str)
 
static void SetWarningStream (std::ostream *output)
 
static void SetWarningStream (Logger::Stream::Pointer stream)
 
static void Warning (const std::string &msg)
 
static void Warning (const std::string &filename, int line, const std::string &msg)
 

Detailed Description

Log mechanism to display debug message, warnings and errors.

The logger class is implemented with the possibility to print debug message, warnings and errors on different Logger::Stream. By default the debug messages are printed on the standard output (std::cout), while the warnings and errors are printed on the standard error (std::cerr). To use the log mechanism, you only need to include the header btkLogger.h and use one of the static methods Logger::Debug(), Logger::Warning(), or Logger::Error(), depending of the type of message you want to print. To simplify the writing of logs with the automatic detection of the filename and line number, three macros are proposed:

The debug logs are only available when the code is compiled in debug mode (when the symbol NDEBUG is not defined).

The diplayed log can be split in 4 parts:

There are four verbose modes for the display of the logs which can be selected with the method SetVerboseMode(). By default, when the library is compiled in debug mode, the verbose mode is set to Logger::Detailed. In release mode, this is set to Logger::Normal mode. You have also the mode Logger::Quiet where nothing is displayed. The fourh mode is Logger::MessageOnly and show only the given message to the method whitout prefix nor affix. Depending of the selected verbose mode, each log can be printed as the following:

If the prefix and affix are empty, the empty square brackets will not be printed.

The prefix and affix strings can be set with the method SetPrefix(), SetDebugAffix(), SetWarningAffix(), SetErrorAffix().

It is possible to select other output streams than std::cout and std::cerr using the method SetDebugStream(), SetWarningStream(), and SetErrorStream().

An example to use this logger is:

* #include <btkLogger.h>
*
* int main(int argc, char *argv[])
* {
* btk::Logger::Debug("My message");
* btk::Logger::Debug("test.cpp", 42, "Other message with specific filename and line number");
* btk::Logger::Debug(__FILE__, __LINE__, "Another message with automatic detection of the filename and line number");
* return 0;
* };
*

Member Enumeration Documentation

Proposed mode for the display of the log message.

Enumerator
Quiet 

Do not display any message

MessageOnly 

Display only the message

Normal 

Display the message as well as the prefix and log affix.

Detailed 

Same as Normal but add also file information from where the log where written (if these informations are given).

Member Function Documentation

void btk::Logger::Debug ( const std::string &  msg)
static

Write the message msg to the debug stream

Note
Setting the verbose mode to Normal or Detailed will have the same effect using this method as the file informations (filename, line number) are not given
void btk::Logger::Debug ( const std::string &  filename,
int  line,
const std::string &  msg 
)
static

Write the message msg to the debug stream.

void btk::Logger::Error ( const std::string &  msg)
static

Write the message msg to the error stream.

Note
Setting the verbose mode to Normal or Detailed will have the same effect using this method as the file informations (filename, line number) are not given.
void btk::Logger::Error ( const std::string &  filename,
int  line,
const std::string &  msg 
)
static

Write the message msg to the error stream.

const std::string & btk::Logger::GetDebugAffix ( )
static

Gets the string used to indicate that the log is a debug message.

Logger::Stream::Pointer btk::Logger::GetDebugStream ( )
static

Returns the stream used for the debug logs.

const std::string & btk::Logger::GetErrorAffix ( )
static

Gets the string used to indicate that the log is an error.

Logger::Stream::Pointer btk::Logger::GetErrorStream ( )
static

Returns the stream used for the error logs.

const std::string & btk::Logger::GetPrefix ( )
static

Returns the prefix used by the logger. The prefix should contain a string for the library or application which use the logger.

Logger::VerboseMode btk::Logger::GetVerboseMode ( )
static

Returns the current verbose mode.

const std::string & btk::Logger::GetWarningAffix ( )
static

Gets the string used to indicate that the log is a warning.

Logger::Stream::Pointer btk::Logger::GetWarningStream ( )
static

Returns the stream used for the warning logs.

void btk::Logger::SetDebugAffix ( const std::string &  str)
static

Sets the string used to indicate that the log is a debug message.

void btk::Logger::SetDebugStream ( std::ostream *  output)
static

Convenient method to create a Logger::Stream object from an output stream use for the debug messages.

void btk::Logger::SetDebugStream ( Logger::Stream::Pointer  stream)
static

Sets the stream used for the debug logs.

void btk::Logger::SetErrorAffix ( const std::string &  str)
static

Sets the string used to indicate that the log is an error.

void btk::Logger::SetErrorStream ( std::ostream *  output)
static

Convenient method to create a Logger::Stream object from an output stream use for the error messages.

void btk::Logger::SetErrorStream ( Logger::Stream::Pointer  stream)
static

Sets the stream used for the error logs.

void btk::Logger::SetPrefix ( const std::string &  str)
static

Sets the prefix used by the logger.

void btk::Logger::SetVerboseMode ( Logger::VerboseMode  mode)
static

Sets the verbose mode.

void btk::Logger::SetWarningAffix ( const std::string &  str)
static

Sets the string used to indicate that the log is a warning.

void btk::Logger::SetWarningStream ( std::ostream *  output)
static

Convenient method to create a Logger::Stream object from an output stream use for the warning messages.

void btk::Logger::SetWarningStream ( Logger::Stream::Pointer  stream)
static

Sets the stream used for the warning logs.

void btk::Logger::Warning ( const std::string &  msg)
static

Write the message msg to the warning stream.

Note
Setting the verbose mode to Normal or Detailed will have the same effect using this method as the file informations (filename, line number) are not given.
void btk::Logger::Warning ( const std::string &  filename,
int  line,
const std::string &  msg 
)
static

Write the message msg to the warning stream.