9 #ifndef SCARAB_LOGGER_HH_ 10 #define SCARAB_LOGGER_HH_ 25 #ifndef LOGGER_UTILITY_MACROS_ 26 #define LOGGER_UTILITY_MACROS_ 28 #define msvc_bug_fix(m, args) m args 33 #define va_num_args(...) expand( va_num_args_impl(__VA_ARGS__, 5,4,3,2,1)) 34 #define va_num_args_impl(_1,_2,_3,_4,_5,N,...) N 37 #define macro_dispatcher(func, ...) macro_dispatcher_(func, va_num_args(__VA_ARGS__)) 38 #define macro_dispatcher_(func, nargs) macro_dispatcher__(func, nargs) 39 #define macro_dispatcher__(func, nargs) func ## nargs 44 #define COLOR_NORMAL "0" 45 #define COLOR_BRIGHT "1" 46 #define COLOR_FOREGROUND_RED "31" 47 #define COLOR_FOREGROUND_GREEN "32" 48 #define COLOR_FOREGROUND_YELLOW "33" 49 #define COLOR_FOREGROUND_BLUE "34" 50 #define COLOR_FOREGROUND_CYAN "36" 51 #define COLOR_FOREGROUND_WHITE "37" 52 #define COLOR_PREFIX "\033[" 53 #define COLOR_SUFFIX "m" 54 #define COLOR_SEPARATOR ";" 137 Location(
const char*
const fileName =
"",
const char*
const functionName =
"",
int lineNumber = -1) :
138 fLineNumber(lineNumber), fFileName(fileName), fFunctionName(functionName)
156 logger(
const char* name = 0);
158 logger(
const std::string& name);
167 bool IsLevelEnabled(
ELevel level)
const;
179 void SetLevel(
ELevel level)
const;
184 void UseGlobalLevel()
const;
195 static void SetGlobalLevel(
ELevel level);
201 static void SetColored(
bool flag);
207 static void SetOutStream(std::ostream* stream);
213 static void SetErrStream(std::ostream* stream);
232 Log(ELevel::eTrace, message, loc);
242 Log(ELevel::eDebug, message, loc);
252 Log(ELevel::eInfo, message, loc);
262 Log(ELevel::eProg, message, loc);
272 Log(ELevel::eWarn, message, loc);
282 Log(ELevel::eError, message, loc);
292 Log(ELevel::eFatal, message, loc);
304 #define __DEFAULT_LOGGER scarab::logger::GetRootLogger() 306 #define __LOG_LOCATION scarab::logger::Location(__FILE__, __FUNC__, __LINE__) 307 #define __LOG_LOG_4(I,L,M,O) \ 309 if (I.IsLevelEnabled(scarab::logger::ELevel::e##L)) { \ 310 static bool _sLoggerMarker = false; \ 311 if (!O || !_sLoggerMarker) { \ 312 _sLoggerMarker = true; \ 313 std::ostringstream stream; stream << M; \ 314 I.Log(scarab::logger::ELevel::e##L, stream.str(), __LOG_LOCATION); \ 320 #define __LOG_LOG_3(I,L,M) __LOG_LOG_4(I,L,M,false) 321 #define __LOG_LOG_2(L,M) __LOG_LOG_4(__DEFAULT_LOGGER,L,M,false) 322 #define __LOG_LOG_1(M) __LOG_LOG_4(__DEFAULT_LOGGER,Debug,M,false) 324 #define __LOG_TRACE_2(I,M) __LOG_LOG_4(I,Trace,M,false) 325 #define __LOG_TRACE_1(M) __LOG_LOG_4(__DEFAULT_LOGGER,Trace,M,false) 327 #define __LOG_DEBUG_2(I,M) __LOG_LOG_4(I,Debug,M,false) 328 #define __LOG_DEBUG_1(M) __LOG_LOG_4(__DEFAULT_LOGGER,Debug,M,false) 330 #define __LOG_INFO_2(I,M) __LOG_LOG_4(I,Info,M,false) 331 #define __LOG_INFO_1(M) __LOG_LOG_4(__DEFAULT_LOGGER,Info,M,false) 333 #define __LOG_PROG_2(I,M) __LOG_LOG_4(I,Prog,M,false) 334 #define __LOG_PROG_1(M) __LOG_LOG_4(__DEFAULT_LOGGER,Prog,M,false) 336 #define __LOG_WARN_2(I,M) __LOG_LOG_4(I,Warn,M,false) 337 #define __LOG_WARN_1(M) __LOG_LOG_4(__DEFAULT_LOGGER,Warn,M,false) 339 #define __LOG_ERROR_2(I,M) __LOG_LOG_4(I,Error,M,false) 340 #define __LOG_ERROR_1(M) __LOG_LOG_4(__DEFAULT_LOGGER,Error,M,false) 342 #define __LOG_FATAL_2(I,M) __LOG_LOG_4(I,Fatal,M,false) 343 #define __LOG_FATAL_1(M) __LOG_LOG_4(__DEFAULT_LOGGER,Fatal,M,false) 345 #define __LOG_ASSERT_3(I,C,M) if (!(C)) { __LOG_ERROR_2(I,M) } 346 #define __LOG_ASSERT_2(C,M) __LOG_ASSERT_3(__DEFAULT_LOGGER,C,M) 349 #define __LOG_LOG_ONCE_3(I,L,M) __LOG_LOG_4(I,L,M,true) 350 #define __LOG_LOG_ONCE_2(L,M) __LOG_LOG_4(__DEFAULT_LOGGER,L,M,true) 351 #define __LOG_LOG_ONCE_1(M) __LOG_LOG_4(__DEFAULT_LOGGER,Debug,M,true) 353 #define __LOG_TRACE_ONCE_2(I,M) __LOG_LOG_4(I,Trace,M,true) 354 #define __LOG_TRACE_ONCE_1(M) __LOG_LOG_4(__DEFAULT_LOGGER,Trace,M,true) 356 #define __LOG_DEBUG_ONCE_2(I,M) __LOG_LOG_4(I,Debug,M,true) 357 #define __LOG_DEBUG_ONCE_1(M) __LOG_LOG_4(__DEFAULT_LOGGER,Debug,M,true) 359 #define __LOG_INFO_ONCE_2(I,M) __LOG_LOG_4(I,Info,M,true) 360 #define __LOG_INFO_ONCE_1(M) __LOG_LOG_4(__DEFAULT_LOGGER,Info,M,true) 362 #define __LOG_PROG_ONCE_2(I,M) __LOG_LOG_4(I,Prog,M,true) 363 #define __LOG_PROG_ONCE_1(M) __LOG_LOG_4(__DEFAULT_LOGGER,Prog,M,true) 365 #define __LOG_WARN_ONCE_2(I,M) __LOG_LOG_4(I,Warn,M,true) 366 #define __LOG_WARN_ONCE_1(M) __LOG_LOG_4(__DEFAULT_LOGGER,Warn,M,true) 368 #define __LOG_ERROR_ONCE_2(I,M) __LOG_LOG_4(I,Error,M,true) 369 #define __LOG_ERROR_ONCE_1(M) __LOG_LOG_4(__DEFAULT_LOGGER,Error,M,true) 371 #define __LOG_FATAL_ONCE_2(I,M) __LOG_LOG_4(I,Fatal,M,true) 372 #define __LOG_FATAL_ONCE_1(M) __LOG_LOG_4(__DEFAULT_LOGGER,Fatal,M,true) 377 #define LOGGER(I,K) static scarab::logger I(K); 381 #define LOG(...) macro_dispatcher(__LOG_LOG_, __VA_ARGS__)(__VA_ARGS__) 386 #define LTRACE(...) macro_dispatcher(__LOG_TRACE_, __VA_ARGS__)(__VA_ARGS__) 387 #define LDEBUG(...) macro_dispatcher(__LOG_DEBUG_, __VA_ARGS__)(__VA_ARGS__) 389 #define LINFO(...) macro_dispatcher(__LOG_INFO_, __VA_ARGS__)(__VA_ARGS__) 390 #define LPROG(...) macro_dispatcher(__LOG_PROG_, __VA_ARGS__)(__VA_ARGS__) 391 #define LWARN(...) macro_dispatcher(__LOG_WARN_, __VA_ARGS__)(__VA_ARGS__) 392 #define LERROR(...) macro_dispatcher(__LOG_ERROR_, __VA_ARGS__)(__VA_ARGS__) 393 #define LFATAL(...) macro_dispatcher(__LOG_FATAL_, __VA_ARGS__)(__VA_ARGS__) 394 #define LASSERT(...) macro_dispatcher(__LOG_ASSERT_, __VA_ARGS__)(__VA_ARGS__) 396 #define LOG_ONCE(...) macro_dispatcher(__LOG_LOG_ONCE_, __VA_ARGS__)(__VA_ARGS__) 398 #define LTRACE_ONCE(...) 399 #define LDEBUG_ONCE(...) 401 #define LTRACE_ONCE(...) macro_dispatcher(__LOG_TRACE_ONCE_, __VA_ARGS__)(__VA_ARGS__) 402 #define LDEBUG_ONCE(...) macro_dispatcher(__LOG_DEBUG_ONCE_, __VA_ARGS__)(__VA_ARGS__) 404 #define LINFO_ONCE(...) macro_dispatcher(__LOG_INFO_ONCE_, __VA_ARGS__)(__VA_ARGS__) 405 #define LPROG_ONCE(...) macro_dispatcher(__LOG_PROG_ONCE_, __VA_ARGS__)(__VA_ARGS__) 406 #define LWARN_ONCE(...) macro_dispatcher(__LOG_WARN_ONCE_, __VA_ARGS__)(__VA_ARGS__) 407 #define LERROR_ONCE(...) macro_dispatcher(__LOG_ERROR_ONCE_, __VA_ARGS__)(__VA_ARGS__) 408 #define LFATAL_ONCE(...) macro_dispatcher(__LOG_FATAL_ONCE_, __VA_ARGS__)(__VA_ARGS__) 412 #define LOG(I, ...) __LOG_LOG_2(I, __VA_ARGS__) 414 #define LTRACE(I, ...) 415 #define LDEBUG(I, ...) 417 #define LTRACE(I, ...) __LOG_TRACE_2(I, __VA_ARGS__) 418 #define LDEBUG(I, ...) __LOG_DEBUG_2(I, __VA_ARGS__) 420 #define LINFO(I, ...) __LOG_INFO_2(I, __VA_ARGS__) 421 #define LPROG(I, ...) __LOG_PROG_2(I, __VA_ARGS__) 422 #define LWARN(I, ...) __LOG_WARN_2(I, __VA_ARGS__) 423 #define LERROR(I, ...) __LOG_ERROR_2(I, __VA_ARGS__) 424 #define LFATAL(I, ...) __LOG_FATAL_2(I, __VA_ARGS__) 425 #define LASSERT(I, ...) __LOG_ASSERT_2(I, __VA_ARGS__) 427 #define LOG_ONCE(I, ...) __LOG_LOG_ONCE_2(I, __VA_ARGS__) 429 #define LTRACE_ONCE(I, ...) 430 #define LDEBUG_ONCE(I, ...) 432 #define LTRACE_ONCE(I, ...) __LOG_TRACE_ONCE_2(I, __VA_ARGS__) 433 #define LDEBUG_ONCE(I, ...) __LOG_DEBUG_ONCE_2(I, __VA_ARGS__) 435 #define LINFO_ONCE(I, ...) __LOG_INFO_ONCE_2(I, __VA_ARGS__) 436 #define LPROG_ONCE(I, ...) __LOG_PROG_ONCE_2(I, __VA_ARGS__) 437 #define LWARN_ONCE(I, ...) __LOG_WARN_ONCE_2(I, __VA_ARGS__) 438 #define LERROR_ONCE(I, ...) __LOG_ERROR_ONCE_2(I, __VA_ARGS__) 439 #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())