BTK
0.3dev.0
Open-source library to visualize/process biomechanical data
|
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) |
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:
btkDebugMacro(msg)
: alias for the code btk::Logger::Debug(FILE, LINE, msg)
;btkWarningMacro(msg)
: alias for the code btk::Logger::Warning(FILE, LINE, msg)
;btkErrorMacro(msg)
: alias for the code btk::Logger::Error(FILE, LINE, msg)
;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:
message
[prefix log_affix] message
[prefix log_affix] filename (line): message
(filename and line must be given to the method)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:
Proposed mode for the display of the log message.
|
static |
Write the message msg
to the debug stream
|
static |
Write the message msg
to the debug stream.
|
static |
Write the message msg
to the error stream.
|
static |
Write the message msg
to the error stream.
|
static |
Gets the string used to indicate that the log is a debug message.
|
static |
Returns the stream used for the debug logs.
|
static |
Gets the string used to indicate that the log is an error.
|
static |
Returns the stream used for the error logs.
|
static |
Returns the prefix used by the logger. The prefix should contain a string for the library or application which use the logger.
|
static |
Returns the current verbose mode.
|
static |
Gets the string used to indicate that the log is a warning.
|
static |
Returns the stream used for the warning logs.
|
static |
Sets the string used to indicate that the log is a debug message.
|
static |
Convenient method to create a Logger::Stream object from an output stream use for the debug messages.
|
static |
Sets the stream used for the debug logs.
|
static |
Sets the string used to indicate that the log is an error.
|
static |
Convenient method to create a Logger::Stream object from an output stream use for the error messages.
|
static |
Sets the stream used for the error logs.
|
static |
Sets the prefix used by the logger.
|
static |
Sets the verbose mode.
|
static |
Sets the string used to indicate that the log is a warning.
|
static |
Convenient method to create a Logger::Stream object from an output stream use for the warning messages.
|
static |
Sets the stream used for the warning logs.
|
static |
Write the message msg
to the warning stream.
|
static |
Write the message msg
to the warning stream.