Elements 6.3.3
A C++ base framework for the Euclid Software.
Loading...
Searching...
No Matches

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

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";
Logging API of the Elements framework.
Definition Logging.h:93
void error(const std::string &logMessage)
Definition Logging.cpp:134
void debug(const std::string &logMessage)
Definition Logging.cpp:110
static Logging getLogger(const std::string &name="")
Definition Logging.cpp:75
void info(const std::string &logMessage)
Definition Logging.cpp:118

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 73 of file Logging.cpp.

References m_log4cppLogger.

Referenced by getLogger(), and log().

Member Function Documentation

◆ debug() [1/3]

Logging::LogMessageStream Elements::Logging::debug ( )

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 114 of file Logging.cpp.

References m_log4cppLogger.

◆ debug() [2/3]

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

Logs a debug message using format specifiers.

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

References debug(), and info().

Here is the call graph for this function:

◆ debug() [3/3]

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

Logs a debug message.

Parameters
logMessageThe message to log

Definition at line 110 of file Logging.cpp.

References m_log4cppLogger.

Referenced by debug().

◆ error() [1/3]

Logging::LogMessageStream Elements::Logging::error ( )

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 137 of file Logging.cpp.

References m_log4cppLogger.

◆ error() [2/3]

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

Logs an error message using format specifiers.

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

References error(), and fatal().

Here is the call graph for this function:

◆ error() [3/3]

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

Logs an error message.

Parameters
logMessageThe message to log

Definition at line 134 of file Logging.cpp.

References m_log4cppLogger.

Referenced by error(), and warn().

◆ fatal() [1/3]

Logging::LogMessageStream Elements::Logging::fatal ( )

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 145 of file Logging.cpp.

References m_log4cppLogger.

◆ fatal() [2/3]

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

Logs a fatal message using format specifiers.

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

References fatal(), and log().

Here is the call graph for this function:

◆ fatal() [3/3]

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

Logs a fatal message.

Parameters
logMessageThe message to log

Definition at line 141 of file Logging.cpp.

References m_log4cppLogger.

Referenced by error(), and fatal().

◆ getLogger()

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

Returns an instance of Elements::Logging which can be used for logging messages of different severities.

Parameters
nameThe name to use for identifying the logger messages
Returns
A logger instance

Definition at line 75 of file Logging.cpp.

References Elements::getLogLayout(), and Logging().

Here is the call graph for this function:

◆ info() [1/3]

Logging::LogMessageStream Elements::Logging::info ( )

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 122 of file Logging.cpp.

References m_log4cppLogger.

◆ info() [2/3]

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

Logs an info message using format specifiers.

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

References info(), and warn().

Here is the call graph for this function:

◆ info() [3/3]

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

Logs an info message.

Parameters
logMessageThe message to log

Definition at line 118 of file Logging.cpp.

References m_log4cppLogger.

Referenced by debug(), and info().

◆ log() [1/2]

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

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

References Logging().

Here is the call graph for this function:

◆ log() [2/2]

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

Logs a message.

Parameters
levelThe logging level of the message
logMessageThe message to log

Definition at line 149 of file Logging.cpp.

References m_log4cppLogger.

Referenced by fatal().

◆ 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 87 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 99 of file Logging.cpp.

References Elements::getLogLayout().

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

Here is the call graph for this function:

◆ warn() [1/3]

Logging::LogMessageStream Elements::Logging::warn ( )

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 130 of file Logging.cpp.

References m_log4cppLogger.

◆ warn() [2/3]

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

Logs a warning message using format specifiers.

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

References error(), and warn().

Here is the call graph for this function:

◆ warn() [3/3]

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

Logs a warning message.

Parameters
logMessageThe message to log

Definition at line 126 of file Logging.cpp.

References m_log4cppLogger.

Referenced by info(), and warn().

Member Data Documentation

◆ m_log4cppLogger

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

Definition at line 263 of file Logging.h.

Referenced by debug(), debug(), error(), error(), fatal(), fatal(), info(), info(), log(), Logging(), warn(), and warn().


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