Logging API of the Elements framework.
The Elements::Logging class provides the logging API of the Elements framework. To use the logging API the Elements::Logging::getLogger method can be used to retrieve a logger instance, which can be further used for logging messages of different severities. For construction of more complicated messages, the printf style and stream style syntax are supported. For example:
logger.
debug(
"A debug message");
logger.
info(
"A value %d in a printf style info message", 15);
logger.
error() <<
"A value " << 15 <<
" in a steam style error message";
The name given as parameter of the Elements::Logging::getLogger method can be used for identification of the log messages and for further tuning of the underlying logging framework.
The format of the logged messages follows the format:
YYYY-MM-DDTHH:MM:SSZ LOGGER LEVEL : MESSAGE
For example, the previous code snippet will produce the following messages:
2014-03-17T16:20:20CET name DEBUG : A
debug message
2014-03-17T16:20:20CET name INFO : A value 15 in a
printf style
info message
2014-03-17T16:20:20CET name ERROR : A value 15 in a steam style
error message
By default the logging level is set to INFO and the default behaviour is to forward all the messages to the standard error stream. This behaviour can be modified by using the method Elements::Logging::setLevel, which can be used to set the level to show, and the method Elements::Logging::setLogFile, which can be used to redirect the messages in a file (in addition to the standard error stream). Note that these methods have a global effect to the application.
If the Elements::Program API is used, the logging level and the log file can be set by using the command line parameters –log-level and –log-file and no direct use of the Elements::Logging::setLevel and Elements::Logging::setLogFile should be performed. Exception of this rule is any log messages which are sent before the command line parameters are handled (like global or static variable initialisations, or any other action before the call of the main method). These messages (without an explicit call to the Elements::Logging::setLogFile method) will only appear in the standard error stream.
Definition at line 93 of file Logging.h.
void Elements::Logging::setLogFile |
( |
const Path::Item & |
fileName | ) |
|
|
static |
Sets the file to store the log messages.
This call has effect to all the loggers already retrieved, as well as loggers which will be retrieved in the future. There can be only one global file in which the messages are redirected. Multiple calls of this method will just switch the file the messages are stored in. Note that this method does not affect any file handlers attached to specific loggers by using the underlying framework configuration methods.
If an empty string is given as fileName, then the loggers will stop storing the messages in any files.
- Parameters
-
fileName | The file where the log messages will be stored |
Definition at line 87 of file Logging.cpp.
References Elements::getLogLayout().
Referenced by Elements::ProgramManager::setup().