36 #define XERUS_LOGSTREAM xerus::misc::internal::get_fileStream() 39 #define XERUS_LOGSTREAM std::cerr 53 void log_timestamp(std::ostream &_out,
const char* _file,
int _line,
const char* _lvl);
59 #ifdef XERUS_LOG_BUFFER 81 extern std::stringstream
current;
82 extern std::stringstream
old;
92 #define XERUS_STRINGIFY2( x) #x 93 #define XERUS_STRINGIFY(x) XERUS_STRINGIFY2(x) 100 #define XERUS_COMPILE_TIME_EVAL(e) (std::integral_constant<decltype(e), e>::value) 110 #ifdef XERUS_LOG_BUFFER 111 #define XERUS_NAMED_LOGGER_LOGBUFFER(lvl) \ 112 if (::xerus::misc::internal::LogFlag<xerus::misc::internal::log_namehash(XERUS_STRINGIFY(lvl))>::flag != xerus::misc::internal::NOT_LOGGING && !xerus::misc::internal::silenced) { \ 113 ::xerus::misc::internal::log_timestamp(xerus::misc::internal::buffer::current, __FILE__, __LINE__, XERUS_STRINGIFY(lvl)); \ 114 xerus::misc::internal::buffer::current << tmpStream.str(); \ 115 xerus::misc::internal::buffer::checkSwitch(); \ 116 if (XERUS_COMPILE_TIME_EVAL(xerus::misc::internal::log_namehash(XERUS_STRINGIFY(lvl))==xerus::misc::internal::log_namehash("error"))) { \ 117 xerus::misc::internal::buffer::dump_log(std::string("error invoked:\n")+tmpStream.str()); \ 119 if (XERUS_COMPILE_TIME_EVAL(xerus::misc::internal::log_namehash(XERUS_STRINGIFY(lvl))==xerus::misc::internal::log_namehash("critical"))) { \ 120 xerus::misc::internal::buffer::dump_log(std::string("critical error invoked:\n")+tmpStream.str()); \ 122 if (XERUS_COMPILE_TIME_EVAL(xerus::misc::internal::log_namehash(XERUS_STRINGIFY(lvl))==xerus::misc::internal::log_namehash("fatal"))) { \ 123 xerus::misc::internal::buffer::dump_log(std::string("fatal error invoked:\n")+tmpStream.str()); \ 126 #else // no log buffer 127 #define XERUS_NAMED_LOGGER_LOGBUFFER(lvl) 139 #define XERUS_LOG(lvl, ...) \ 140 if (::xerus::misc::internal::LogFlag<xerus::misc::internal::log_namehash(XERUS_STRINGIFY(lvl))>::flag != xerus::misc::internal::NOT_LOGGING) { \ 141 std::stringstream tmpStream; \ 142 tmpStream << __VA_ARGS__ << std::endl; \ 143 xerus::misc::internal::namedLoggerMutex.lock(); \ 144 if (::xerus::misc::internal::LogFlag<xerus::misc::internal::log_namehash(XERUS_STRINGIFY(lvl))>::flag == xerus::misc::internal::LOGGING_FULL && !xerus::misc::internal::silenced) { \ 145 ::xerus::misc::internal::log_timestamp(XERUS_LOGSTREAM, __FILE__, __LINE__, XERUS_STRINGIFY(lvl)); \ 146 XERUS_LOGSTREAM << tmpStream.str() << std::flush; \ 148 XERUS_NAMED_LOGGER_LOGBUFFER(lvl) \ 149 xerus::misc::internal::namedLoggerMutex.unlock(); \ 150 if (::xerus::misc::internal::LogFlag<xerus::misc::internal::log_namehash(XERUS_STRINGIFY(lvl))>::flag == xerus::misc::internal::LOGGING_EXCEPTION ) { \ 151 XERUS_THROW(xerus::misc::generic_error() << __FILE__ << ":" << __LINE__ << ": " XERUS_STRINGIFY(lvl) " invoked:\n" << tmpStream.str() << "callstack:\n" << xerus::misc::get_call_stack()); \ 162 #define XERUS_LOG_SHORT(lvl, ...) \ 163 if (::xerus::misc::internal::LogFlag<xerus::misc::internal::log_namehash(XERUS_STRINGIFY(lvl))>::flag != xerus::misc::internal::NOT_LOGGING) { \ 164 std::stringstream tmpStream; \ 165 tmpStream << __VA_ARGS__ << std::endl; \ 166 xerus::misc::internal::namedLoggerMutex.lock(); \ 167 if (::xerus::misc::internal::LogFlag<xerus::misc::internal::log_namehash(XERUS_STRINGIFY(lvl))>::flag == xerus::misc::internal::LOGGING_FULL && !xerus::misc::internal::silenced) { \ 168 ::xerus::misc::internal::log_timestamp(XERUS_LOGSTREAM, XERUS_STRINGIFY(lvl)); \ 169 XERUS_LOGSTREAM << tmpStream.str() << std::flush; \ 171 XERUS_NAMED_LOGGER_LOGBUFFER(lvl) \ 172 xerus::misc::internal::namedLoggerMutex.unlock(); \ 173 if (::xerus::misc::internal::LogFlag<xerus::misc::internal::log_namehash(XERUS_STRINGIFY(lvl))>::flag == xerus::misc::internal::LOGGING_EXCEPTION ) { \ 174 XERUS_THROW(xerus::misc::generic_error() << XERUS_STRINGIFY(lvl) " error invoked:\n" << tmpStream.str() << "callstack:\n" << xerus::misc::get_call_stack()); \ 185 #define XERUS_LOG_ONCE(lvl, ...) \ 187 static bool logged = false;\ 189 XERUS_LOG(lvl, __VA_ARGS__);\ 198 #define XERUS_IS_LOGGING(lvl) \ 199 (::xerus::misc::internal::LogFlag<xerus::misc::internal::log_namehash(XERUS_STRINGIFY(lvl))>::flag != xerus::misc::internal::NOT_LOGGING) 202 namespace xerus {
namespace misc {
namespace internal {
211 #define XERUS_SET_LOGGING(lvl, value) \ 212 namespace xerus { namespace misc { namespace internal { \ 213 template<> struct LogFlag<xerus::misc::internal::log_namehash(XERUS_STRINGIFY(lvl))>{ static const int flag = value; }; \ 219 #define XERUS_SET_DEFAULT_LOG_LEVELS \ 220 XERUS_SET_LOGGING(fatal, xerus::misc::internal::LOGGING_EXCEPTION)\ 221 XERUS_SET_LOGGING(critical, xerus::misc::internal::LOGGING_EXCEPTION)\ 222 XERUS_SET_LOGGING(error, xerus::misc::internal::LOGGING_EXCEPTION)\ 223 XERUS_SET_LOGGING(warning, xerus::misc::internal::LOGGING_FULL)\ 224 XERUS_SET_LOGGING(info, xerus::misc::internal::LOGGING_FULL)\ 225 XERUS_SET_LOGGING(debug, xerus::misc::internal::LOGGING_ON_ERROR) 227 #ifdef XERUS_LOG_ERROR 228 #undef XERUS_SET_DEFAULT_LOG_LEVELS 229 #define XERUS_SET_DEFAULT_LOG_LEVELS \ 230 XERUS_SET_LOGGING(fatal, xerus::misc::internal::LOGGING_EXCEPTION)\ 231 XERUS_SET_LOGGING(critical, xerus::misc::internal::LOGGING_EXCEPTION)\ 232 XERUS_SET_LOGGING(error, xerus::misc::internal::LOGGING_EXCEPTION)\ 233 XERUS_SET_LOGGING(warning, xerus::misc::internal::LOGGING_ON_ERROR)\ 234 XERUS_SET_LOGGING(info, xerus::misc::internal::LOGGING_ON_ERROR)\ 235 XERUS_SET_LOGGING(debug, xerus::misc::internal::LOGGING_ON_ERROR) 238 #ifdef XERUS_LOG_WARNING 239 #undef XERUS_SET_DEFAULT_LOG_LEVELS 240 #define XERUS_SET_DEFAULT_LOG_LEVELS \ 241 XERUS_SET_LOGGING(fatal, xerus::misc::internal::LOGGING_EXCEPTION)\ 242 XERUS_SET_LOGGING(critical, xerus::misc::internal::LOGGING_EXCEPTION)\ 243 XERUS_SET_LOGGING(error, xerus::misc::internal::LOGGING_EXCEPTION)\ 244 XERUS_SET_LOGGING(warning, xerus::misc::internal::LOGGING_FULL)\ 245 XERUS_SET_LOGGING(info, xerus::misc::internal::LOGGING_ON_ERROR)\ 246 XERUS_SET_LOGGING(debug, xerus::misc::internal::LOGGING_ON_ERROR) 249 #ifdef XERUS_LOG_INFO 250 #undef XERUS_SET_DEFAULT_LOG_LEVELS 251 #define XERUS_SET_DEFAULT_LOG_LEVELS \ 252 XERUS_SET_LOGGING(fatal, xerus::misc::internal::LOGGING_EXCEPTION)\ 253 XERUS_SET_LOGGING(critical, xerus::misc::internal::LOGGING_EXCEPTION)\ 254 XERUS_SET_LOGGING(error, xerus::misc::internal::LOGGING_EXCEPTION)\ 255 XERUS_SET_LOGGING(warning, xerus::misc::internal::LOGGING_FULL)\ 256 XERUS_SET_LOGGING(info, xerus::misc::internal::LOGGING_FULL)\ 257 XERUS_SET_LOGGING(debug, xerus::misc::internal::LOGGING_ON_ERROR) 260 #ifdef XERUS_LOG_DEBUG 261 #undef XERUS_SET_DEFAULT_LOG_LEVELS 262 #define XERUS_SET_DEFAULT_LOG_LEVELS \ 263 XERUS_SET_LOGGING(fatal, xerus::misc::internal::LOGGING_EXCEPTION)\ 264 XERUS_SET_LOGGING(critical, xerus::misc::internal::LOGGING_EXCEPTION)\ 265 XERUS_SET_LOGGING(error, xerus::misc::internal::LOGGING_EXCEPTION)\ 266 XERUS_SET_LOGGING(warning, xerus::misc::internal::LOGGING_FULL)\ 267 XERUS_SET_LOGGING(info, xerus::misc::internal::LOGGING_FULL)\ 268 XERUS_SET_LOGGING(debug, xerus::misc::internal::LOGGING_FULL) std::string logFilePrefix
void dump_log(std::string _comment)
std::ostream & get_fileStream()
The main namespace of xerus.
constexpr uint64_t log_namehash(const char *x)
Hashes a given c-string using the FNV-1a standard hash.
Header file for the call-stack functionality.
Header file for xerus::misc::generic_error exception class.
static const auto LOGGING_ON_ERROR
std::mutex namedLoggerMutex
#define XERUS_SET_DEFAULT_LOG_LEVELS
std::stringstream current
void log_timestamp(std::ostream &_out, const char *_file, int _line, const char *_lvl)
std::chrono::system_clock::time_point programStartTime