3 * @brief Declaration of functions for printing log messages and/or terminating program after a fatal error
13 inline std::string methodName(const std::string& prettyFunction)
15 size_t colons = prettyFunction.find("::");
16 size_t begin = prettyFunction.substr(0,colons).rfind(" ") + 1;
17 size_t end = prettyFunction.rfind("(") - begin;
19 return prettyFunction.substr(begin,end) + "()";
22 #define __METHOD_NAME__ methodName(__PRETTY_FUNCTION__).c_str()
29 enum {LOG_EMERG, LOG_ALERT, LOG_CRIT, LOG_ERR, LOG_WARNING, LOG_NOTICE, LOG_INFO, LOG_DEBUG};
32 //To get around a 'pedantic' C99 rule that you must have at least 1 variadic arg, combine fmt into that.
33 #define Log(level, ...) LogEx(level, __METHOD_NAME__, __FILE__, __LINE__, __VA_ARGS__)
34 #define Fatal(...) FatalEx(__METHOD_NAME__, __FILE__, __LINE__, __VA_ARGS__)
36 #define Debug(...) LogEx(LOG_DEBUG, __func__, __FILE__, __LINE__, __VA_ARGS__)
37 #define Error(...) LogEx(LOG_ERR, __func__, __FILE__, __LINE__, __VA_ARGS__)
38 #define Warn(...) LogEx(LOG_WARN, __func__, __FILE__, __LINE__, __VA_ARGS__)
41 extern void LogEx(int level, const char * funct, const char * file, int line, ...); // General function for printing log messages to stderr
42 extern void FatalEx(const char * funct, const char * file, int line, ...); // Function that deals with a fatal error (prints a message, then exits the program).