Elements 6.3.1
A C++ base framework for the Euclid Software.
|
Logging API of the Elements framework. More...
#include <Logging.h>
Classes | |
class | LogMessageStream |
A helper class for logging messages using the "<<" operator. More... | |
Public Member Functions | |
void | debug (const std::string &logMessage) |
template<typename... Args> | |
void | debug (const char *stringFormat, Args &&... args) |
LogMessageStream | debug () |
void | info (const std::string &logMessage) |
template<typename... Args> | |
void | info (const char *stringFormat, Args &&... args) |
LogMessageStream | info () |
void | warn (const std::string &logMessage) |
template<typename... Args> | |
void | warn (const char *stringFormat, Args &&... args) |
LogMessageStream | warn () |
void | error (const std::string &logMessage) |
template<typename... Args> | |
void | error (const char *stringFormat, Args &&... args) |
LogMessageStream | error () |
void | fatal (const std::string &logMessage) |
template<typename... Args> | |
void | fatal (const char *stringFormat, Args &&... args) |
LogMessageStream | fatal () |
void | log (log4cpp::Priority::Value level, const std::string &logMessage) |
template<typename... Args> | |
void | log (log4cpp::Priority::Value level, const char *stringFormat, Args &&... args) |
Static Public Member Functions | |
static Logging | getLogger (const std::string &name="") |
static void | setLevel (std::string level) |
Sets the global message level. | |
static void | setLogFile (const Path::Item &fileName) |
Sets the file to store the log messages. | |
Private Member Functions | |
Logging (log4cpp::Category &log4cppLogger) | |
Private Attributes | |
log4cpp::Category & | m_log4cppLogger |
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:
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:
For example, the previous code snippet will produce the following messages:
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.
|
explicitprivate |
Definition at line 73 of file Logging.cpp.
Logging::LogMessageStream Elements::Logging::debug | ( | ) |
Returns an object which can be used for logging a debug message using the "<<" operator.
Definition at line 114 of file Logging.cpp.
References m_log4cppLogger.
void Elements::Logging::debug | ( | const char * | stringFormat, |
Args &&... | args ) |
Logs a debug message using format specifiers.
stringFormat | The message containing the format specifiers |
args | The values to replace the format specifiers with |
void Elements::Logging::debug | ( | const std::string & | logMessage | ) |
Logs a debug message.
logMessage | The message to log |
Definition at line 110 of file Logging.cpp.
References m_log4cppLogger.
Logging::LogMessageStream Elements::Logging::error | ( | ) |
Returns an object which can be used for logging a error message using the "<<" operator.
Definition at line 137 of file Logging.cpp.
References m_log4cppLogger.
void Elements::Logging::error | ( | const char * | stringFormat, |
Args &&... | args ) |
Logs an error message using format specifiers.
stringFormat | The message containing the format specifiers |
args | The values to replace the format specifiers with |
void Elements::Logging::error | ( | const std::string & | logMessage | ) |
Logs an error message.
logMessage | The message to log |
Definition at line 134 of file Logging.cpp.
References m_log4cppLogger.
Logging::LogMessageStream Elements::Logging::fatal | ( | ) |
Returns an object which can be used for logging a fatal message using the "<<" operator.
Definition at line 145 of file Logging.cpp.
References m_log4cppLogger.
void Elements::Logging::fatal | ( | const char * | stringFormat, |
Args &&... | args ) |
Logs a fatal message using format specifiers.
stringFormat | The message containing the format specifiers |
args | The values to replace the format specifiers with |
void Elements::Logging::fatal | ( | const std::string & | logMessage | ) |
Logs a fatal message.
logMessage | The message to log |
Definition at line 141 of file Logging.cpp.
References m_log4cppLogger.
|
static |
Returns an instance of Elements::Logging which can be used for logging messages of different severities.
name | The name to use for identifying the logger messages |
Definition at line 75 of file Logging.cpp.
References Elements::getLogLayout().
Logging::LogMessageStream Elements::Logging::info | ( | ) |
Returns an object which can be used for logging a info message using the "<<" operator.
Definition at line 122 of file Logging.cpp.
References m_log4cppLogger.
void Elements::Logging::info | ( | const char * | stringFormat, |
Args &&... | args ) |
Logs an info message using format specifiers.
stringFormat | The message containing the format specifiers |
args | The values to replace the format specifiers with |
void Elements::Logging::info | ( | const std::string & | logMessage | ) |
Logs an info message.
logMessage | The message to log |
Definition at line 118 of file Logging.cpp.
References m_log4cppLogger.
void Elements::Logging::log | ( | log4cpp::Priority::Value | level, |
const char * | stringFormat, | ||
Args &&... | args ) |
Logs an log message using a level and format specifiers.
level | The logging level of the message |
stringFormat | The message containing the format specifiers |
args | The values to replace the format specifiers with |
void Elements::Logging::log | ( | log4cpp::Priority::Value | level, |
const std::string & | logMessage ) |
Logs a message.
level | The logging level of the message |
logMessage | The message to log |
Definition at line 149 of file Logging.cpp.
References m_log4cppLogger.
|
static |
Sets the global message level.
This call has effect to all the loggers already retrieved as well as loggers which will be retrieved in the future. Exceptions are loggers which have been fine tuned using the underlying framework configuration methods.
level | The new message level |
Definition at line 87 of file Logging.cpp.
References std::endl(), Elements::LOG_LEVEL, and std::stringstream::str().
Referenced by Elements::ProgramManager::setup().
|
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.
fileName | The file where the log messages will be stored |
Definition at line 99 of file Logging.cpp.
References Elements::getLogLayout().
Referenced by Elements::ProgramManager::setup().
Logging::LogMessageStream Elements::Logging::warn | ( | ) |
Returns an object which can be used for logging a warn message using the "<<" operator.
Definition at line 130 of file Logging.cpp.
References m_log4cppLogger.
void Elements::Logging::warn | ( | const char * | stringFormat, |
Args &&... | args ) |
Logs a warning message using format specifiers.
stringFormat | The message containing the format specifiers |
args | The values to replace the format specifiers with |
void Elements::Logging::warn | ( | const std::string & | logMessage | ) |
Logs a warning message.
logMessage | The message to log |
Definition at line 126 of file Logging.cpp.
References m_log4cppLogger.
|
private |