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...
|
| 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) |
|
|
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...
|
|
template<Log L, bool ASSERTS>
class Logger< L, ASSERTS >
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.
- Template Parameters
-
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;
template<Log L, bool ASSERTS>
template<typename Arg1 , typename... Args>
void Logger< L, ASSERTS >::createMessage |
( |
std::stringstream & |
msg, |
|
|
const char * |
fmt, |
|
|
Arg1 && |
arg, |
|
|
Args &&... |
args |
|
) |
| |
|
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.
- 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. |
527 bool doSkipNext =
false;
528 while (*fmt !=
'%' || doSkipNext)
534 if (*fmt ==
'\\' && !doSkipNext)
552 precision = std::atoi(fmt);
553 while (isdigit(*fmt))
557 if (std::ispunct(*fmt))
560 if (std::isdigit(*fmt))
562 width = std::atoi(fmt);
563 while (isdigit(*fmt))
576 else if (std::ispunct(*fmt))
579 if (std::isdigit(*fmt))
581 width = std::atoi(fmt);
582 while (isdigit(*fmt))
593 if (width != 0 && precision != 0)
595 msg << std::setprecision(precision) << std::left << std::setw(width) << arg;
597 else if (precision != 0)
599 msg << std::setprecision(precision) << arg;
603 msg << std::left << std::setw(width) << arg;
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 % ...
Definition: Logger.h:524
Referenced by Logger< L, ASSERTS >::createMessage(), and Logger< L, ASSERTS >::operator()().
template<Log L, bool ASSERTS>
template<typename... Args>
void Logger< L, ASSERTS >::createMessage |
( |
std::stringstream & |
msg, |
|
|
const char * |
fmt, |
|
|
Flusher |
arg, |
|
|
Args &&... |
args |
|
) |
| |
|
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.
- Parameters
-
[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. |
631 #ifndef MERCURYDPM_DEBUG
#define MERCURYDPM_LOGLEVEL
Definition: Logger.h:38
Flusher doFlush_
Can prevent the logger from flushing the buffer via std::endl. doFlush_ is set automatically based on...
Definition: Logger.h:316
References Logger< L, ASSERTS >::createMessage(), Logger< L, ASSERTS >::doFlush_, FLUSH, MERCURYDPM_LOGLEVEL, NO_FLUSH, and VERBOSE.
template<Log L, bool ASSERTS>
template<Log LOGLEVEL, typename ... Args>
std::enable_if<!((L < LOGLEVEL) && (MERCURYDPM_LOGLEVEL < LOGLEVEL)), void>::type Logger< L, ASSERTS >::operator() |
( |
const LL< LOGLEVEL > |
log, |
|
|
const char *format |
UNUSED, |
|
|
Args &&... arg |
UNUSED |
|
) |
| |
|
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.
- Parameters
-
[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. |
353 std::stringstream msgstream;
std::function< void(std::string, std::string, Flusher)> onFatal
Definition: Logger.h:159
std::function< void(std::string, std::string, Flusher)> onDebug
Definition: Logger.h:164
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.