The Micro C++ Library
|
The class Log provides a simple logging facility. More...
#include <micxx.hxx>
Inherits micxx::traits::NonCopyable.
Static Public Member Functions | |
static void | configure (const Properties &properties) |
static void | destroy () |
Static Public Attributes | |
static unsigned char | debugLevel |
The current debugging threshold. | |
static std::ostream * | debug |
The logging stream for the debug category, or 0 , if debug is not enabled. | |
static std::ostream * | info |
The logging stream for the info category, or 0 , if info is not enabled. | |
static std::ostream * | warn |
The logging stream for the warn category, or 0 , if warn is not enabled. | |
static std::ostream * | error |
The logging stream for the error category, or 0 , if error is not enabled. | |
static std::ostream * | logFile |
If a log file has been configured through the property logfile , this member will keep the reference to it. | |
static Mutex * | mutex |
The Mutex used to synchronize access to the shared output logging stream. |
The class Log provides a simple logging facility.
The class Log provides four logging categories debug, info, warn and error. By default only warn and error are enabled and the output is directed to cerr
.
The Log class itself does only provide static members, that represent the shared logging categories or streams and the optional mutex, that is used to synchronize the access to these logging streams. If no such mutex is configured, than access to the shared logging streams is not synchronized by the logging macros.
Configuration is either done by setting the Log class members directly or by calling Log::configure(const Properties&) with a set of properties like
debug = (true| | If true this property sets Log::debug either to std::cout or to Log::logFile which will be set by property logfile (if specified). If false sets Log::debug to 0 . |
debug.level = n | This property set Log::debugLevel to n. |
info = (true| | If true this property sets Log::info either to std::cout or to Log::logFile which will be set by property logfile (if specified). If false sets Log::info to 0 . |
warn = (true| | If true this property sets Log::warn either to std::cout or to Log::logFile which will be set by property logfile (if specified). If false sets Log::warn to 0 . |
error = (true| | If true this property sets Log::error either to std::cout or to Log::logFile which will be set by property logfile (if specified). If false sets Log::error to 0 . |
logfile = filename | If specified this property sets Log:logFile specified by filename. Otherwise sets Log::logFile to 0 . |
The logging streams typically must not be used directly. Instead the following macros are provided
In all macros expr syntactically could be any C++ expression that may be used between two shift operators like in expr1 <<
expr <<
expr2. expr is only evaluated, if the output logging stream for the specific category is enabled. In that case, expr is written to the output logging stream used by the specific macro.
When using the macro MICXX_DEBUG(level,expr), expr is only logged to the debug category Log::debug, if the Log::debug category is enabled and if level is less than Log::debugLevel.
static void micxx::Log::configure | ( | const Properties & | properties | ) | [static] |
Configures the Log class by evaluating the list of properties. This method will also delete any existing Log::mutex or any existing Log::logFile before the new set of properties is evaluated.
static void micxx::Log::destroy | ( | ) | [static] |
This will delete Log::mutex and Log::logFile if set and will reset the class to the default configuration.
std::ostream* micxx::Log::debug [static] |
The logging stream for the debug category, or 0
, if debug is not enabled.
unsigned char micxx::Log::debugLevel [static] |
The current debugging threshold.
Only debugging statements with level less than debugLevel will be logged.
std::ostream* micxx::Log::error [static] |
The logging stream for the error category, or 0
, if error is not enabled.
std::ostream* micxx::Log::info [static] |
The logging stream for the info category, or 0
, if info is not enabled.
std::ostream* micxx::Log::logFile [static] |
If a log file has been configured through the property logfile
, this member will keep the reference to it.
logfile
. Mutex* micxx::Log::mutex [static] |
The Mutex used to synchronize access to the shared output logging stream.
std::ostream* micxx::Log::warn [static] |
The logging stream for the warn category, or 0
, if warn is not enabled.