32 #include <type_traits>
37 #ifndef MERCURYDPM_LOGLEVEL
38 #define MERCURYDPM_LOGLEVEL Log::DEFAULT
42 #define CG_LOGLEVEL Log::DEFAULT
50 #ifdef MERCURYDPM_FORCE_ASSERTS
51 #define MERCURYDPM_ASSERTS true
53 #ifdef MERCURYDPM_NO_ASSERTS
54 #define MERCURYDPM_ASSERTS false
57 #define MERCURYDPM_ASSERTS false
59 #define MERCURYDPM_ASSERTS true
142 return ((
static_cast<signed char>(rhs)) <= (
static_cast<signed char>(lhs)));
178 template<Log L = Log::DEFAULT,
bool ASSERTS = MERCURYDPM_ASSERTS>
303 template<Log L,
bool ASSERTS>
349 template<
Log LOGLEVEL,
typename ... Args>
353 std::stringstream msgstream;
388 template<
Log LOGLEVEL,
typename... Args>
389 typename std::enable_if<L < LOGLEVEL && MERCURYDPM_LOGLEVEL < LOGLEVEL, void>::type
399 template<
Log LOGLEVEL,
typename... Args>
403 (*this)(
log, format.c_str(), arg...);
420 template<
typename... Args>
421 typename std::enable_if<(ASSERTS) && (
sizeof...(Args) >= 0),
void>::type
422 assert_debug(
bool assertion,
const char* format, Args&& ... arg)
424 assert_always(assertion, format, arg...);
427 template<
typename... Args>
428 typename std::enable_if<!((ASSERTS) &&
sizeof...(Args) >= 0),
void>::type
429 assert_debug(
bool assertion,
const char* format, Args&& ... arg)
437 template<
typename... Args>
438 void assert_debug(
bool assertion,
const std::string format, Args&& ... arg)
440 assert_debug(assertion, format.c_str(), arg...);
443 template<
typename... Args>
444 void assert_always(
bool assertion,
const char* format, Args&& ... arg)
448 std::stringstream msgstream;
458 template<
typename... Args>
459 void assert_always(
bool assertion,
const std::string format, Args&& ... arg)
461 assert_always(assertion, format.c_str(), arg...);
468 template<
typename... Args>
470 void log(
const Log loglevel,
const std::string& format, Args&& ... arg)
474 std::stringstream msgstream;
523 template<
typename Arg1,
typename... Args>
525 Arg1&& arg, Args&& ... args)
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;
625 template<
typename... Args>
631 #ifndef MERCURYDPM_DEBUG
651 template<
typename Arg1>
654 bool doSkipNext =
false;
655 while (*fmt !=
'%' || doSkipNext)
660 if (*fmt ==
'\\' && !doSkipNext)
678 precision = std::atoi(fmt);
679 while (isdigit(*fmt))
683 if (std::ispunct(*fmt))
686 if (std::isdigit(*fmt))
688 width = std::atoi(fmt);
689 while (isdigit(*fmt))
702 else if (std::ispunct(*fmt))
705 if (std::isdigit(*fmt))
707 width = std::atoi(fmt);
708 while (isdigit(*fmt))
719 if (width != 0 && precision != 0)
721 msg << std::setprecision(precision) << std::left << std::setw(width) << arg << fmt;
723 else if (precision != 0)
725 msg << std::setprecision(precision) << arg << fmt;
729 msg << std::left << std::setw(width) << arg << fmt;
764 #if !MERCURYDPM_ASSERTS
765 #define assert(e,...) assert(true,"")
768 #ifdef MERCURYDPM_USE_MPI
#define MERCURYDPM_DEPRECATED
Definition: GeneralDefine.h:37
#define UNUSED
Definition: GeneralDefine.h:39
Logger< CG_LOGLEVEL > cgLogger
LL< Log::VERBOSE > VERBOSE
Verbose information.
Definition: Logger.cc:57
LL< Log::INFO > INFO
Info log level.
Definition: Logger.cc:55
LL< Log::DEBUG > DEBUG
Debug information.
Definition: Logger.cc:58
Log
The different loglevels.
Definition: Logger.h:130
LL< Log::FATAL > FATAL
Fatal log level.
Definition: Logger.cc:52
Flusher
The Logger class provides ability to write log messages in your own customized format.
Definition: Logger.h:115
#define MERCURYDPM_LOGLEVEL
Definition: Logger.h:38
LL< Log::ERROR > ERROR
Error log level.
Definition: Logger.cc:53
LoggerOutput * loggerOutput
Declaration of the output functions.
Definition: Logger.cc:283
Logger< MERCURYDPM_LOGLEVEL > logger
constexpr bool operator<=(const Log rhs, const Log lhs)
Internally used to filter on loglevel. Do not edit, as this is required for an optimised logger.
Definition: Logger.h:140
LL< Log::WARN > WARN
Warning log level.
Definition: Logger.cc:54
LL< Log::DEFAULT > DEFAULT
Default log level.
Definition: Logger.cc:56
Tag for template metaprogramming.
Definition: Logger.h:195
Default functions for output generation.
Definition: Logger.h:157
std::function< void(std::string, std::string, Flusher)> onVerbose
Definition: Logger.h:163
std::function< void(std::string, std::string, Flusher)> onFatal
Definition: Logger.h:159
std::function< void(std::string, std::string, Flusher)> onWarn
Definition: Logger.h:161
std::function< void(std::string, std::string, Flusher)> onError
Definition: Logger.h:160
std::function< void(std::string, std::string, Flusher)> onInfo
Definition: Logger.h:162
std::function< void(std::string, std::string, Flusher)> onDebug
Definition: Logger.h:164
the Logger class is the main class of the logger implementation. It holds all the functions which inv...
Definition: Logger.h:305
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...
Definition: Logger.h:626
const std::string module
The module name of this actual logger.
Definition: Logger.h:311
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 ...
Definition: Logger.h:652
void createMessage(std::stringstream &msg, const char *message)
Terminating case / no argument call Overloaded function for a logger message without arguments.
Definition: Logger.h:745
Logger(const std::string name)
constructor
Definition: Logger.h:325
~Logger()=default
destructor
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.
Definition: Logger.h:351
Flusher doFlush_
Can prevent the logger from flushing the buffer via std::endl. doFlush_ is set automatically based on...
Definition: Logger.h:316
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
Mdouble log(Mdouble Power)
Definition: ExtendedMath.cc:104
std::string name
Definition: MercuryProb.h:48