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. |
506 bool doSkipNext =
false;
507 while (*fmt !=
'%' || doSkipNext)
513 if (*fmt ==
'\\' && !doSkipNext)
531 precision = std::atoi(fmt);
532 while (isdigit(*fmt))
536 if (std::ispunct(*fmt))
539 if (std::isdigit(*fmt))
541 width = std::atoi(fmt);
542 while (isdigit(*fmt))
555 else if (std::ispunct(*fmt))
558 if (std::isdigit(*fmt))
560 width = std::atoi(fmt);
561 while (isdigit(*fmt))
572 if (width != 0 && precision != 0)
574 msg << std::setprecision(precision) << std::left << std::setw(width) << arg;
576 else if (precision != 0)
578 msg << std::setprecision(precision) << arg;
582 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:503
args
Definition: compute_granudrum_aor.py:143
References compute_granudrum_aor::args.
Referenced by Logger< L, ASSERTS >::createMessage(), and Logger< L, ASSERTS >::operator()().
template<Log L, bool ASSERTS>
template<typename... 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.
- 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. |
610 #ifndef MERCURYDPM_DEBUG
#define MERCURYDPM_LOGLEVEL
Definition: Logger.h:17
Flusher doFlush_
Can prevent the logger from flushing the buffer via std::endl. doFlush_ is set automatically based on...
Definition: Logger.h:295
References compute_granudrum_aor::args, 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>
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. |
332 std::stringstream msgstream;
std::function< void(std::string, std::string, Flusher)> onFatal
Definition: Logger.h:138
std::function< void(std::string, std::string, Flusher)> onDebug
Definition: Logger.h:143
std::string format(const std::string &str, const std::vector< std::string > &find, const std::vector< std::string > &replace)
Definition: openglsupport.cpp:217
References Logger< L, ASSERTS >::createMessage(), Logger< L, ASSERTS >::doFlush_, ERROR, FATAL, FLUSH, format(), INFO, loggerOutput, Logger< L, ASSERTS >::module, LoggerOutput::onDebug, LoggerOutput::onError, LoggerOutput::onFatal, LoggerOutput::onInfo, LoggerOutput::onVerbose, LoggerOutput::onWarn, VERBOSE, and WARN.