Elements
6.0.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. More... | |
static void | setLogFile (const Path::Item &fileName) |
Sets the file to store the log messages. More... | |
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 61 of file Logging.cpp.
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
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 63 of file Logging.cpp.
References Elements::getLogLayout().
Referenced by Elements::Examples::crashingFunction(), Elements::Examples::CfitsioExample::mainMethod(), Elements::Examples::WcsExample::mainMethod(), Elements::Examples::HealpixExample::mainMethod(), Elements::Examples::GnuAstroExample::mainMethod(), Elements::Examples::CCfitsExample::mainMethod(), Elements::Examples::EigenExample::mainMethod(), Elements::Examples::XercesExample::mainMethod(), Elements::Examples::GslExample::mainMethod(), Elements::Examples::OpenMPExample::mainMethod(), Elements::Examples::FftwExample::mainMethod(), Elements::Examples::SimpleProgramExample::mainMethod(), Elements::Examples::ProgramExampleWithArguments::mainMethod(), ExtProgramExample::mainMethod(), Elements::Examples::ProgramExample::mainMethod(), Elements::Examples::myLocalLogTestFunc(), and Elements::Examples::testCallBack().
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
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 75 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 87 of file Logging.cpp.
References Elements::getLogLayout().
Referenced by Elements::ProgramManager::setup().
|
inline |
|
inline |
|
inline |
|
private |