Elements  6.2
A C++ base framework for the Euclid Software.
Classes | Public Member Functions | Static Public Member Functions | Private Member Functions | Private Attributes | List of all members

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
 

Detailed Description

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.

Constructor & Destructor Documentation

◆ Logging()

Elements::Logging::Logging ( log4cpp::Category &  log4cppLogger)
explicitprivate

Definition at line 61 of file Logging.cpp.

Member Function Documentation

◆ debug() [1/3]

LogMessageStream Elements::Logging::debug ( )
inline

Returns an object which can be used for logging a debug message using the "<<" operator.

Returns
An object used for logging a debug message using the "<<" opearator

Definition at line 162 of file Logging.h.

◆ debug() [2/3]

template<typename... Args>
void Elements::Logging::debug ( const char *  stringFormat,
Args &&...  args 
)
inline

Logs a debug message using format specifiers.

Parameters
stringFormatThe message containing the format specifiers
argsThe values to replace the format specifiers with

Definition at line 153 of file Logging.h.

◆ debug() [3/3]

void Elements::Logging::debug ( const std::string logMessage)
inline

Logs a debug message.

Parameters
logMessageThe message to log

Definition at line 143 of file Logging.h.

◆ error() [1/3]

LogMessageStream Elements::Logging::error ( )
inline

Returns an object which can be used for logging a error message using the "<<" operator.

Returns
An object used for logging a error message using the "<<" opearator

Definition at line 243 of file Logging.h.

◆ error() [2/3]

template<typename... Args>
void Elements::Logging::error ( const char *  stringFormat,
Args &&...  args 
)
inline

Logs an error message using format specifiers.

Parameters
stringFormatThe message containing the format specifiers
argsThe values to replace the format specifiers with

Definition at line 234 of file Logging.h.

◆ error() [3/3]

void Elements::Logging::error ( const std::string logMessage)
inline

Logs an error message.

Parameters
logMessageThe message to log

Definition at line 224 of file Logging.h.

◆ fatal() [1/3]

LogMessageStream Elements::Logging::fatal ( )
inline

Returns an object which can be used for logging a fatal message using the "<<" operator.

Returns
An object used for logging a fatal message using the "<<" opearator

Definition at line 270 of file Logging.h.

◆ fatal() [2/3]

template<typename... Args>
void Elements::Logging::fatal ( const char *  stringFormat,
Args &&...  args 
)
inline

Logs a fatal message using format specifiers.

Parameters
stringFormatThe message containing the format specifiers
argsThe values to replace the format specifiers with

Definition at line 261 of file Logging.h.

◆ fatal() [3/3]

void Elements::Logging::fatal ( const std::string logMessage)
inline

Logs a fatal message.

Parameters
logMessageThe message to log

Definition at line 251 of file Logging.h.

◆ getLogger()

Logging Elements::Logging::getLogger ( const std::string name = "")
static

◆ info() [1/3]

LogMessageStream Elements::Logging::info ( )
inline

Returns an object which can be used for logging a info message using the "<<" operator.

Returns
An object used for logging a info message using the "<<" opearator

Definition at line 189 of file Logging.h.

◆ info() [2/3]

template<typename... Args>
void Elements::Logging::info ( const char *  stringFormat,
Args &&...  args 
)
inline

Logs an info message using format specifiers.

Parameters
stringFormatThe message containing the format specifiers
argsThe values to replace the format specifiers with

Definition at line 180 of file Logging.h.

◆ info() [3/3]

void Elements::Logging::info ( const std::string logMessage)
inline

Logs an info message.

Parameters
logMessageThe message to log

Definition at line 170 of file Logging.h.

◆ log() [1/2]

template<typename... Args>
void Elements::Logging::log ( log4cpp::Priority::Value  level,
const char *  stringFormat,
Args &&...  args 
)
inline

Logs an log message using a level and format specifiers.

Parameters
levelThe logging level of the message
stringFormatThe message containing the format specifiers
argsThe values to replace the format specifiers with

Definition at line 290 of file Logging.h.

◆ log() [2/2]

void Elements::Logging::log ( log4cpp::Priority::Value  level,
const std::string logMessage 
)
inline

Logs a message.

Parameters
levelThe logging level of the message
logMessageThe message to log

Definition at line 279 of file Logging.h.

◆ setLevel()

void Elements::Logging::setLevel ( std::string  level)
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.

Parameters
levelThe 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().

Here is the call graph for this function:

◆ setLogFile()

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
fileNameThe file where the log messages will be stored

Definition at line 87 of file Logging.cpp.

References Elements::getLogLayout().

Referenced by Elements::ProgramManager::setup().

Here is the call graph for this function:

◆ warn() [1/3]

LogMessageStream Elements::Logging::warn ( )
inline

Returns an object which can be used for logging a warn message using the "<<" operator.

Returns
An object used for logging a warn message using the "<<" opearator

Definition at line 216 of file Logging.h.

◆ warn() [2/3]

template<typename... Args>
void Elements::Logging::warn ( const char *  stringFormat,
Args &&...  args 
)
inline

Logs a warning message using format specifiers.

Parameters
stringFormatThe message containing the format specifiers
argsThe values to replace the format specifiers with

Definition at line 207 of file Logging.h.

◆ warn() [3/3]

void Elements::Logging::warn ( const std::string logMessage)
inline

Logs a warning message.

Parameters
logMessageThe message to log

Definition at line 197 of file Logging.h.

Member Data Documentation

◆ m_log4cppLogger

log4cpp::Category& Elements::Logging::m_log4cppLogger
private

Definition at line 297 of file Logging.h.


The documentation for this class was generated from the following files:
Elements::Logging
Logging API of the Elements framework.
Definition: Logging.h:93
Elements::Logging::info
LogMessageStream info()
Definition: Logging.h:189
std::printf
T printf(T... args)
Elements::Logging::error
LogMessageStream error()
Definition: Logging.h:243
Elements::Logging::debug
void debug(const std::string &logMessage)
Definition: Logging.h:143
Elements::Logging::debug
LogMessageStream debug()
Definition: Logging.h:162
Elements::Logging::info
void info(const std::string &logMessage)
Definition: Logging.h:170
Elements::Logging::getLogger
static Logging getLogger(const std::string &name="")
Definition: Logging.cpp:63
Elements::Logging::error
void error(const std::string &logMessage)
Definition: Logging.h:224