32 #include <type_traits>
35 #ifndef MERCURY_LOGLEVEL
36 #define MERCURY_LOGLEVEL Log::DEFAULT
45 #ifdef MERCURY_FORCE_ASSERTS
46 #define MERCURY_ASSERTS true
48 #ifdef MERCURY_NO_ASSERTS
49 #define MERCURY_ASSERTS false
52 #define MERCURY_ASSERTS false
54 #define MERCURY_ASSERTS true
167 return ((static_cast<signed char>(rhs)) <= (static_cast<signed char>(lhs)));
185 std::function<void(std::string, std::string)>
onFatal;
186 std::function<void(std::string, std::string)>
onError;
187 std::function<void(std::string, std::string)>
onWarn;
188 std::function<void(std::string, std::string)>
onInfo;
189 std::function<void(std::string, std::string)>
onVerbose;
190 std::function<void(std::string, std::string)>
onDebug;
204 template<Log L = Log::DEFAULT,
bool ASSERTS = MERCURY_ASSERTS>
class Logger;
314 template<Log L,
bool ASSERTS>
351 template<
Log LOGLEVEL,
typename ... Args>
352 typename std::enable_if<!((L < LOGLEVEL) && (MERCURY_LOGLEVEL < LOGLEVEL)), void>::type
355 std::stringstream msgstream;
385 template<
Log LOGLEVEL,
typename... Args>
386 typename std::enable_if<L < LOGLEVEL || MERCURY_LOGLEVEL < LOGLEVEL, void>::type
391 template<
Log LOGLEVEL,
typename... Args>
392 typename std::enable_if<L < LOGLEVEL || MERCURY_LOGLEVEL < LOGLEVEL, void>::type
427 template<
typename... Args>
428 typename std::enable_if<(ASSERTS) && (
sizeof...(Args) >= 0),
void>::type
429 assert(
bool assertion,
const char* format, Args&&... arg)
431 assert_always(assertion, format, arg...);
434 template<
typename... Args>
435 typename std::enable_if<!((ASSERTS) &&
sizeof...(Args) >= 0),
void>::type
436 assert(
bool assertion,
const char* format, Args&&... arg)
440 template<
typename... Args>
441 void assert(
bool assertion,
const std::string format, Args&&... arg)
443 assert(assertion, format.c_str(), arg...);
446 template<
typename... Args>
447 void assert_always(
bool assertion,
const char* format, Args&&... arg)
451 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>
469 void log(
const Log loglevel,
const std::string& format, Args&&... arg)
473 std::stringstream msgstream;
506 template<
typename Arg1,
typename... Args>
508 Arg1&& arg, Args&&... args)
510 bool doSkipNext =
false;
511 while (*fmt !=
'%' || doSkipNext)
517 if (*fmt ==
'\\'&& !doSkipNext)
538 template<
typename Arg1>
541 bool doSkipNext =
false;
542 while (*fmt !=
'%' || doSkipNext)
547 if (*fmt ==
'\\' && !doSkipNext)
584 #define assert(e,...) assert(true,"")
LoggerOutput * loggerOutput
Declaration of the output functions. If the output needs to be redirected, please swap the loggerOutp...
See How to use the logger for details on how to use the logger.
LL< Log::INFO > INFO
Info log level.
LL< Log::DEBUG > DEBUG
Debug information.
LL< Log::ERROR > ERROR
Error log level.
void createMessage(std::stringstream &msg, const char *message)
Terminating case / no argument call.
std::enable_if<!((L< LOGLEVEL)&&(MERCURY_LOGLEVEL< LOGLEVEL)), void >::type operator()(const LL< LOGLEVEL > log, const char *format, Args &&...arg)
std::function< void(std::string, std::string)> onError
void createMessage(std::stringstream &msg, const char *fmt, Arg1 &&arg)
Terminating case / argument call.
std::function< void(std::string, std::string)> onDebug
Logger(const std::string name)
constructor
std::function< void(std::string, std::string)> onFatal
Mdouble log(Mdouble Power)
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...
const std::string module
The module name of this actual logger.
std::function< void(std::string, std::string)> onVerbose
Default functions for output generation.
LL< Log::DEFAULT > DEFAULT
Default log level.
std::function< void(std::string, std::string)> onWarn
LL< Log::VERBOSE > VERBOSE
Verbose information.
std::function< void(std::string, std::string)> onInfo
Logger< MERCURY_LOGLEVEL > logger
Log
The different loglevels.
LL< Log::FATAL > FATAL
Fatal log level.
void createMessage(std::stringstream &msg, const char *fmt, Arg1 &&arg, Args &&...args)
Actual implementation to recursively replace all the '' signs by actual values.
LL< Log::WARN > WARN
Warning log level.
Tag for template metaprogramming.