9 #ifndef SCARAB_LOGGER_HH_ 10 #define SCARAB_LOGGER_HH_ 27 #ifndef LOGGER_UTILITY_MACROS_ 28 #define LOGGER_UTILITY_MACROS_ 30 #define msvc_bug_fix(m, args) m args 35 #define va_num_args(...) expand( va_num_args_impl(__VA_ARGS__, 5,4,3,2,1)) 36 #define va_num_args_impl(_1,_2,_3,_4,_5,N,...) N 39 #define macro_dispatcher(func, ...) macro_dispatcher_(func, va_num_args(__VA_ARGS__)) 40 #define macro_dispatcher_(func, nargs) macro_dispatcher__(func, nargs) 41 #define macro_dispatcher__(func, nargs) func ## nargs 46 #define COLOR_NORMAL "0" 47 #define COLOR_BRIGHT "1" 48 #define COLOR_FOREGROUND_RED "31" 49 #define COLOR_FOREGROUND_GREEN "32" 50 #define COLOR_FOREGROUND_YELLOW "33" 51 #define COLOR_FOREGROUND_BLUE "34" 52 #define COLOR_FOREGROUND_CYAN "36" 53 #define COLOR_FOREGROUND_WHITE "37" 54 #define COLOR_PREFIX "\033[" 55 #define COLOR_SUFFIX "m" 56 #define COLOR_SEPARATOR ";" 139 Location(
const char*
const fileName =
"",
const char*
const functionName =
"",
int lineNumber = -1) :
140 fLineNumber(lineNumber), fFileName(fileName), fFunctionName(functionName)
158 logger(
const char* name = 0);
160 logger(
const std::string& name);
169 bool IsLevelEnabled(
ELevel level)
const;
181 void SetLevel(
ELevel level)
const;
186 void UseGlobalLevel()
const;
197 static void SetGlobalLevel(
ELevel level);
203 static void SetColored(
bool flag);
209 static void SetOutStream(std::ostream* stream);
215 static void SetErrStream(std::ostream* stream);
234 Log(ELevel::eTrace, message, loc);
244 Log(ELevel::eDebug, message, loc);
254 Log(ELevel::eInfo, message, loc);
264 Log(ELevel::eProg, message, loc);
274 Log(ELevel::eWarn, message, loc);
284 Log(ELevel::eError, message, loc);
294 Log(ELevel::eFatal, message, loc);
306 #define __DEFAULT_LOGGER scarab::logger::GetRootLogger() 308 #define __LOG_LOCATION scarab::logger::Location(__FILE__, __FUNC__, __LINE__) 309 #define __LOG_LOG_4(I,L,M,O) \ 311 if (I.IsLevelEnabled(scarab::logger::ELevel::e##L)) { \ 312 static bool _sLoggerMarker = false; \ 313 if (!O || !_sLoggerMarker) { \ 314 _sLoggerMarker = true; \ 315 std::ostringstream stream; stream << M; \ 316 I.Log(scarab::logger::ELevel::e##L, stream.str(), __LOG_LOCATION); \ 322 #define __LOG_LOG_3(I,L,M) __LOG_LOG_4(I,L,M,false) 323 #define __LOG_LOG_2(L,M) __LOG_LOG_4(__DEFAULT_LOGGER,L,M,false) 324 #define __LOG_LOG_1(M) __LOG_LOG_4(__DEFAULT_LOGGER,Debug,M,false) 326 #define __LOG_TRACE_2(I,M) __LOG_LOG_4(I,Trace,M,false) 327 #define __LOG_TRACE_1(M) __LOG_LOG_4(__DEFAULT_LOGGER,Trace,M,false) 329 #define __LOG_DEBUG_2(I,M) __LOG_LOG_4(I,Debug,M,false) 330 #define __LOG_DEBUG_1(M) __LOG_LOG_4(__DEFAULT_LOGGER,Debug,M,false) 332 #define __LOG_INFO_2(I,M) __LOG_LOG_4(I,Info,M,false) 333 #define __LOG_INFO_1(M) __LOG_LOG_4(__DEFAULT_LOGGER,Info,M,false) 335 #define __LOG_PROG_2(I,M) __LOG_LOG_4(I,Prog,M,false) 336 #define __LOG_PROG_1(M) __LOG_LOG_4(__DEFAULT_LOGGER,Prog,M,false) 338 #define __LOG_WARN_2(I,M) __LOG_LOG_4(I,Warn,M,false) 339 #define __LOG_WARN_1(M) __LOG_LOG_4(__DEFAULT_LOGGER,Warn,M,false) 341 #define __LOG_ERROR_2(I,M) __LOG_LOG_4(I,Error,M,false) 342 #define __LOG_ERROR_1(M) __LOG_LOG_4(__DEFAULT_LOGGER,Error,M,false) 344 #define __LOG_FATAL_2(I,M) __LOG_LOG_4(I,Fatal,M,false) 345 #define __LOG_FATAL_1(M) __LOG_LOG_4(__DEFAULT_LOGGER,Fatal,M,false) 347 #define __LOG_ASSERT_3(I,C,M) if (!(C)) { __LOG_ERROR_2(I,M) } 348 #define __LOG_ASSERT_2(C,M) __LOG_ASSERT_3(__DEFAULT_LOGGER,C,M) 351 #define __LOG_LOG_ONCE_3(I,L,M) __LOG_LOG_4(I,L,M,true) 352 #define __LOG_LOG_ONCE_2(L,M) __LOG_LOG_4(__DEFAULT_LOGGER,L,M,true) 353 #define __LOG_LOG_ONCE_1(M) __LOG_LOG_4(__DEFAULT_LOGGER,Debug,M,true) 355 #define __LOG_TRACE_ONCE_2(I,M) __LOG_LOG_4(I,Trace,M,true) 356 #define __LOG_TRACE_ONCE_1(M) __LOG_LOG_4(__DEFAULT_LOGGER,Trace,M,true) 358 #define __LOG_DEBUG_ONCE_2(I,M) __LOG_LOG_4(I,Debug,M,true) 359 #define __LOG_DEBUG_ONCE_1(M) __LOG_LOG_4(__DEFAULT_LOGGER,Debug,M,true) 361 #define __LOG_INFO_ONCE_2(I,M) __LOG_LOG_4(I,Info,M,true) 362 #define __LOG_INFO_ONCE_1(M) __LOG_LOG_4(__DEFAULT_LOGGER,Info,M,true) 364 #define __LOG_PROG_ONCE_2(I,M) __LOG_LOG_4(I,Prog,M,true) 365 #define __LOG_PROG_ONCE_1(M) __LOG_LOG_4(__DEFAULT_LOGGER,Prog,M,true) 367 #define __LOG_WARN_ONCE_2(I,M) __LOG_LOG_4(I,Warn,M,true) 368 #define __LOG_WARN_ONCE_1(M) __LOG_LOG_4(__DEFAULT_LOGGER,Warn,M,true) 370 #define __LOG_ERROR_ONCE_2(I,M) __LOG_LOG_4(I,Error,M,true) 371 #define __LOG_ERROR_ONCE_1(M) __LOG_LOG_4(__DEFAULT_LOGGER,Error,M,true) 373 #define __LOG_FATAL_ONCE_2(I,M) __LOG_LOG_4(I,Fatal,M,true) 374 #define __LOG_FATAL_ONCE_1(M) __LOG_LOG_4(__DEFAULT_LOGGER,Fatal,M,true) 379 #define LOGGER(I,K) static scarab::logger I(K); 383 #define LOG(...) macro_dispatcher(__LOG_LOG_, __VA_ARGS__)(__VA_ARGS__) 388 #define LTRACE(...) macro_dispatcher(__LOG_TRACE_, __VA_ARGS__)(__VA_ARGS__) 389 #define LDEBUG(...) macro_dispatcher(__LOG_DEBUG_, __VA_ARGS__)(__VA_ARGS__) 391 #define LINFO(...) macro_dispatcher(__LOG_INFO_, __VA_ARGS__)(__VA_ARGS__) 392 #define LPROG(...) macro_dispatcher(__LOG_PROG_, __VA_ARGS__)(__VA_ARGS__) 393 #define LWARN(...) macro_dispatcher(__LOG_WARN_, __VA_ARGS__)(__VA_ARGS__) 394 #define LERROR(...) macro_dispatcher(__LOG_ERROR_, __VA_ARGS__)(__VA_ARGS__) 395 #define LFATAL(...) macro_dispatcher(__LOG_FATAL_, __VA_ARGS__)(__VA_ARGS__) 396 #define LASSERT(...) macro_dispatcher(__LOG_ASSERT_, __VA_ARGS__)(__VA_ARGS__) 398 #define LOG_ONCE(...) macro_dispatcher(__LOG_LOG_ONCE_, __VA_ARGS__)(__VA_ARGS__) 400 #define LTRACE_ONCE(...) 401 #define LDEBUG_ONCE(...) 403 #define LTRACE_ONCE(...) macro_dispatcher(__LOG_TRACE_ONCE_, __VA_ARGS__)(__VA_ARGS__) 404 #define LDEBUG_ONCE(...) macro_dispatcher(__LOG_DEBUG_ONCE_, __VA_ARGS__)(__VA_ARGS__) 406 #define LINFO_ONCE(...) macro_dispatcher(__LOG_INFO_ONCE_, __VA_ARGS__)(__VA_ARGS__) 407 #define LPROG_ONCE(...) macro_dispatcher(__LOG_PROG_ONCE_, __VA_ARGS__)(__VA_ARGS__) 408 #define LWARN_ONCE(...) macro_dispatcher(__LOG_WARN_ONCE_, __VA_ARGS__)(__VA_ARGS__) 409 #define LERROR_ONCE(...) macro_dispatcher(__LOG_ERROR_ONCE_, __VA_ARGS__)(__VA_ARGS__) 410 #define LFATAL_ONCE(...) macro_dispatcher(__LOG_FATAL_ONCE_, __VA_ARGS__)(__VA_ARGS__) 414 #define LOG(I, ...) __LOG_LOG_2(I, __VA_ARGS__) 416 #define LTRACE(I, ...) 417 #define LDEBUG(I, ...) 419 #define LTRACE(I, ...) __LOG_TRACE_2(I, __VA_ARGS__) 420 #define LDEBUG(I, ...) __LOG_DEBUG_2(I, __VA_ARGS__) 422 #define LINFO(I, ...) __LOG_INFO_2(I, __VA_ARGS__) 423 #define LPROG(I, ...) __LOG_PROG_2(I, __VA_ARGS__) 424 #define LWARN(I, ...) __LOG_WARN_2(I, __VA_ARGS__) 425 #define LERROR(I, ...) __LOG_ERROR_2(I, __VA_ARGS__) 426 #define LFATAL(I, ...) __LOG_FATAL_2(I, __VA_ARGS__) 427 #define LASSERT(I, ...) __LOG_ASSERT_2(I, __VA_ARGS__) 429 #define LOG_ONCE(I, ...) __LOG_LOG_ONCE_2(I, __VA_ARGS__) 431 #define LTRACE_ONCE(I, ...) 432 #define LDEBUG_ONCE(I, ...) 434 #define LTRACE_ONCE(I, ...) __LOG_TRACE_ONCE_2(I, __VA_ARGS__) 435 #define LDEBUG_ONCE(I, ...) __LOG_DEBUG_ONCE_2(I, __VA_ARGS__) 437 #define LINFO_ONCE(I, ...) __LOG_INFO_ONCE_2(I, __VA_ARGS__) 438 #define LPROG_ONCE(I, ...) __LOG_PROG_ONCE_2(I, __VA_ARGS__) 439 #define LWARN_ONCE(I, ...) __LOG_WARN_ONCE_2(I, __VA_ARGS__) 440 #define LERROR_ONCE(I, ...) __LOG_ERROR_ONCE_2(I, __VA_ARGS__) 441 #define LFATAL_ONCE(I, ...) __LOG_FATAL_ONCE_2(I, __VA_ARGS__)
std::string fFunctionName
static logger & GetRootLogger()
void LogWarn(const std::string &message, const Location &loc=Location())
void LogInfo(const std::string &message, const Location &loc=Location())
void LogProg(const std::string &message, const Location &loc=Location())
void LogDebug(const std::string &message, const Location &loc=Location())
void LogTrace(const std::string &message, const Location &loc=Location())
Location(const char *const fileName="", const char *const functionName="", int lineNumber=-1)
std::shared_ptr< Private > fPrivate
void LogFatal(const std::string &message, const Location &loc=Location())
void LogError(const std::string &message, const Location &loc=Location())