|
the Logger class is the main class of the logger implementation. It holds all the functions which invoke certain methods to create messages based on input parameter deductions. More...
#include <Logger.h>
Public Member Functions | |
Logger (const std::string name) | |
constructor More... | |
~Logger ()=default | |
destructor More... | |
template<Log LOGLEVEL, typename ... Args> | |
std::enable_if<!((L< LOGLEVEL) &&(MERCURYDPM_LOGLEVEL< LOGLEVEL)), void >::type | operator() (const LL< LOGLEVEL > log, const char *format UNUSED, Args &&... arg UNUSED) |
Log implementation of this function. More... | |
template<Log LOGLEVEL, typename... Args> | |
std::enable_if< L< LOGLEVEL &&MERCURYDPM_LOGLEVEL< LOGLEVEL, void >::type operator()(const LL< LOGLEVEL > log, const char *format UNUSED, Args &&... arg UNUSED) { } template< Log LOGLEVEL, typename... Args > void operator()(const LL< LOGLEVEL > log, const std::string &format UNUSED, Args &&... arg UNUSED) {(*this)(log, format.c_str(), arg...);} template< typename... Args > typename std::enable_if<(ASSERTS) &&(sizeof...(Args) >=0), void >::type assert_debug(bool assertion, const char *format, Args &&... arg) { assert_always(assertion, format, arg...);} template< typename... Args > typename std::enable_if<!((ASSERTS) &&sizeof...(Args) >=0), void >::type assert_debug(bool assertion, const char *format, Args &&... arg) { } template< typename... Args > void assert_debug(bool assertion, const std::string format, Args &&... arg) { assert_debug(assertion, format.c_str(), arg...);} template< typename... Args > void assert_always(bool assertion, const char *format, Args &&... arg) { if(!assertion) { std::stringstream msgstream;createMessage(msgstream, format, arg...);loggerOutput->onFatal(module, msgstream.str(), doFlush_);} } template< typename... Args > void assert_always(bool assertion, const std::string format, Args &&... arg) { assert_always(assertion, format.c_str(), arg...);} template< typename... Args > MERCURYDPM_DEPRECATED void log(const Log loglevel, const std::string &format, Args &&... arg) { if(loglevel<=L||loglevel<=MERCURYDPM_LOGLEVEL) { std::stringstream msgstream;createMessage(msgstream, format.c_str(), arg...);if(loglevel<=Log::FATAL) { loggerOutput-> | onFatal (module, msgstream.str(), doFlush_) |
Empty body function utilized to suppress logger messages above a certain user defined loglevel L. More... | |
else | if (loglevel<=Log::ERROR) |
else | if (loglevel<=Log::WARN) |
else | if (loglevel<=Log::INFO) |
else | if (loglevel<=Log::VERBOSE) |
Public Attributes | |
else | |
doFlush_ = Flusher::FLUSH | |
Private Member Functions | |
template<typename Arg1 , typename... Args> | |
void | createMessage (std::stringstream &msg, const char *fmt, Arg1 &&arg, Args &&... args) |
Edits the message to a certain format and writes it to a stringstream by recursively replacing all % characters with the arguments values. More... | |
template<typename... Args> | |
void | createMessage (std::stringstream &msg, const char *fmt, Flusher arg, Args &&... args) |
Overloaded version of createMessage to catch arguments of Flusher and suppress input flushing via std::endl. If there is an argument which should be catched from the logger, overloading the function is the way to go. More... | |
template<typename Arg1 > | |
void | createMessage (std::stringstream &msg, const char *fmt, Arg1 &&arg) |
Terminating case / Argument call. Overloaded function for a logger message with only one argument or where only one argument is left. More... | |
void | createMessage (std::stringstream &msg, const char *message) |
Terminating case / no argument call Overloaded function for a logger message without arguments. More... | |
Private Attributes | |
const std::string | module |
The module name of this actual logger. More... | |
Flusher | doFlush_ = Flusher::FLUSH |
Can prevent the logger from flushing the buffer via std::endl. doFlush_ is set automatically based on build and loglevel settings. More... | |
the Logger class is the main class of the logger implementation. It holds all the functions which invoke certain methods to create messages based on input parameter deductions.
L | The log level defined in cMake configuration. Messages of higher level than L are ignored. |
Usage: logger(FATAL, "Error in (here) because % < %!\n", var1, var2) OUTPUT: Error in (here) because 2 < 1!
Define custom loggers by: ifndef HG_LOGLEVEL_CUSTOMMOD define HG_LOGLEVEL_CUSTOMMOD Log::Debug endif Logger<HG_LOGLEVEL_CUSTOMMOD> customLogger;
constructor
[in] | name | The name in this module used in output messages. |
|
inlineprivate |
Terminating case / Argument call. Overloaded function for a logger message with only one argument or where only one argument is left.
[in] | msg | stringstream which represents the output message. |
[in] | fmt | char array of the yet unformatted message. |
[in] | arg | argument to replace the next % character. |
|
inlineprivate |
Edits the message to a certain format and writes it to a stringstream by recursively replacing all % characters with the arguments values.
The creation of messages is divided into three different overloaded functions. the function createMessage is recursively called and each of the functions below is called for a certain case dependent on the amount and type of parameters.
[in] | msg | stringstream which represents the output message. |
[in] | fmt | char array of the yet unformatted message. |
[in] | arg | argument to replace the next % character. |
[in] | args | parameter pack of the remaining arguments. |
Referenced by Logger< L, ASSERTS >::createMessage(), and Logger< L, ASSERTS >::operator()().
|
inlineprivate |
Overloaded version of createMessage to catch arguments of Flusher and suppress input flushing via std::endl. If there is an argument which should be catched from the logger, overloading the function is the way to go.
[in] | msg | stringstream which represents the output message. |
[in] | fmt | char array of the yet unformatted message. |
[in] | arg | argument of type Flusher which will be skipped and does not replace the next % character. |
[in] | args | parameter pack of the remaining parameters. |
References Logger< L, ASSERTS >::createMessage(), Logger< L, ASSERTS >::doFlush_, FLUSH, MERCURYDPM_LOGLEVEL, NO_FLUSH, and VERBOSE.
|
inline |
References Logger< L, ASSERTS >::doFlush_, loggerOutput, Logger< L, ASSERTS >::module, and LoggerOutput::onError.
References Logger< L, ASSERTS >::doFlush_, FLUSH, loggerOutput, Logger< L, ASSERTS >::module, and LoggerOutput::onInfo.
|
inline |
References Logger< L, ASSERTS >::doFlush_, FLUSH, loggerOutput, Logger< L, ASSERTS >::module, and LoggerOutput::onVerbose.
References Logger< L, ASSERTS >::doFlush_, FLUSH, loggerOutput, Logger< L, ASSERTS >::module, and LoggerOutput::onWarn.
std::enable_if<L < LOGLEVEL && MERCURYDPM_LOGLEVEL < LOGLEVEL, void>::type operator()(const LL<LOGLEVEL> log, const char* format UNUSED, Args&& ... arg UNUSED) { } template<Log LOGLEVEL, typename... Args> void operator()(const LL<LOGLEVEL> log, const std::string& format UNUSED, Args&& ... arg UNUSED) { (*this)(log, format.c_str(), arg...); } template<typename... Args> typename std::enable_if<(ASSERTS) && (sizeof...(Args) >= 0), void>::type assert_debug(bool assertion, const char* format, Args&& ... arg) { assert_always(assertion, format, arg...); } template<typename... Args> typename std::enable_if<!((ASSERTS) && sizeof...(Args) >= 0), void>::type assert_debug(bool assertion, const char* format, Args&& ... arg) { } template<typename... Args> void assert_debug(bool assertion, const std::string format, Args&& ... arg) { assert_debug(assertion, format.c_str(), arg...); } template<typename... Args> void assert_always(bool assertion, const char* format, Args&& ... arg) { if (!assertion) { std::stringstream msgstream; createMessage(msgstream, format, arg...); loggerOutput->onFatal(module, msgstream.str(), doFlush_); } } template<typename... Args> void assert_always(bool assertion, const std::string format, Args&& ... arg) { assert_always(assertion, format.c_str(), arg...); } template<typename... Args> MERCURYDPM_DEPRECATED void log(const Log loglevel, const std::string& format, Args&& ... arg) { if (loglevel <= L || loglevel <= MERCURYDPM_LOGLEVEL) { std::stringstream msgstream; createMessage(msgstream, format.c_str(), arg...); if (loglevel <= Log::FATAL) { loggerOutput-> Logger< L, ASSERTS >::onFatal | ( | module | , |
msgstream. | str(), | ||
doFlush_ | |||
) |
Empty body function utilized to suppress logger messages above a certain user defined loglevel L.
|
inline |
Log implementation of this function.
Actual implementation of the log function. If the user defined loglevel L is lower than the called LOGLEVEL it will evaluate to an empty body function below. If L is greater than the called LOGLEVEL it will invoke this function.
[in] | log | Loglevel, either FATAL, ERROR, WARN, INFO, VERBOSE, DEBUG |
[in] | format | Message format, where % can be used as a placeholder for arguments. |
[in] | arg | Any arguments which replace all the % characters. |
References Logger< L, ASSERTS >::createMessage(), Logger< L, ASSERTS >::doFlush_, ERROR, FATAL, FLUSH, INFO, loggerOutput, Logger< L, ASSERTS >::module, LoggerOutput::onDebug, LoggerOutput::onError, LoggerOutput::onFatal, LoggerOutput::onInfo, LoggerOutput::onVerbose, LoggerOutput::onWarn, VERBOSE, and WARN.
|
private |
Can prevent the logger from flushing the buffer via std::endl. doFlush_ is set automatically based on build and loglevel settings.
Referenced by Logger< L, ASSERTS >::createMessage(), Logger< L, ASSERTS >::if(), and Logger< L, ASSERTS >::operator()().
Logger< L, ASSERTS >::doFlush_ = Flusher::FLUSH |
Logger< L, ASSERTS >::else |
|
private |
The module name of this actual logger.
Referenced by Logger< L, ASSERTS >::if(), and Logger< L, ASSERTS >::operator()().