The Micro C++ Library
micxx::Log Class Reference

The class Log provides a simple logging facility. More...

#include <micxx.hxx>

Inherits micxx::traits::NonCopyable.

List of all members.

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 Mutexmutex
 The Mutex used to synchronize access to the shared output logging stream.

Detailed Description

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|false) 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|false) 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|false) 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|false) 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.

Author:
Norbert Klose
Date:
December, 2006

Member Function Documentation

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.


Member Data Documentation

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.

See also:
MICXX_DEBUG
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.

Note:
Call Log::destroy() to delete a logFile which may have been configured through property logfile.

The Mutex used to synchronize access to the shared output logging stream.

Note:
If no such mutex is configured, than access to the shared logging streams is not synchronized by the logging macros.
This member only keeps a reference to the mutex and does not take explicit ownership. Call Log::destroy() to delete mutex if required.
std::ostream* micxx::Log::warn [static]

The logging stream for the warn category, or 0, if warn is not enabled.


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