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;
185 void SetGlobalLevel(
ELevel level)
const;
191 static void SetColored(
bool flag);
197 static void SetOutStream(std::ostream* stream);
203 static void SetErrStream(std::ostream* stream);
222 Log(ELevel::eTrace, message, loc);
232 Log(ELevel::eDebug, message, loc);
242 Log(ELevel::eInfo, message, loc);
252 Log(ELevel::eProg, message, loc);
262 Log(ELevel::eWarn, message, loc);
272 Log(ELevel::eError, message, loc);
282 Log(ELevel::eFatal, message, loc);
294 #define __DEFAULT_LOGGER scarab::logger::GetRootLogger() 296 #define __LOG_LOCATION scarab::logger::Location(__FILE__, __FUNC__, __LINE__) 297 #define __LOG_LOG_4(I,L,M,O) \ 299 if (I.IsLevelEnabled(scarab::logger::ELevel::e##L)) { \ 300 static bool _sLoggerMarker = false; \ 301 if (!O || !_sLoggerMarker) { \ 302 _sLoggerMarker = true; \ 303 std::ostringstream stream; stream << M; \ 304 I.Log(scarab::logger::ELevel::e##L, stream.str(), __LOG_LOCATION); \ 310 #define __LOG_LOG_3(I,L,M) __LOG_LOG_4(I,L,M,false) 311 #define __LOG_LOG_2(L,M) __LOG_LOG_4(__DEFAULT_LOGGER,L,M,false) 312 #define __LOG_LOG_1(M) __LOG_LOG_4(__DEFAULT_LOGGER,Debug,M,false) 314 #define __LOG_TRACE_2(I,M) __LOG_LOG_4(I,Trace,M,false) 315 #define __LOG_TRACE_1(M) __LOG_LOG_4(__DEFAULT_LOGGER,Trace,M,false) 317 #define __LOG_DEBUG_2(I,M) __LOG_LOG_4(I,Debug,M,false) 318 #define __LOG_DEBUG_1(M) __LOG_LOG_4(__DEFAULT_LOGGER,Debug,M,false) 320 #define __LOG_INFO_2(I,M) __LOG_LOG_4(I,Info,M,false) 321 #define __LOG_INFO_1(M) __LOG_LOG_4(__DEFAULT_LOGGER,Info,M,false) 323 #define __LOG_PROG_2(I,M) __LOG_LOG_4(I,Prog,M,false) 324 #define __LOG_PROG_1(M) __LOG_LOG_4(__DEFAULT_LOGGER,Prog,M,false) 326 #define __LOG_WARN_2(I,M) __LOG_LOG_4(I,Warn,M,false) 327 #define __LOG_WARN_1(M) __LOG_LOG_4(__DEFAULT_LOGGER,Warn,M,false) 329 #define __LOG_ERROR_2(I,M) __LOG_LOG_4(I,Error,M,false) 330 #define __LOG_ERROR_1(M) __LOG_LOG_4(__DEFAULT_LOGGER,Error,M,false) 332 #define __LOG_FATAL_2(I,M) __LOG_LOG_4(I,Fatal,M,false) 333 #define __LOG_FATAL_1(M) __LOG_LOG_4(__DEFAULT_LOGGER,Fatal,M,false) 335 #define __LOG_ASSERT_3(I,C,M) if (!(C)) { __LOG_ERROR_2(I,M) } 336 #define __LOG_ASSERT_2(C,M) __LOG_ASSERT_3(__DEFAULT_LOGGER,C,M) 339 #define __LOG_LOG_ONCE_3(I,L,M) __LOG_LOG_4(I,L,M,true) 340 #define __LOG_LOG_ONCE_2(L,M) __LOG_LOG_4(__DEFAULT_LOGGER,L,M,true) 341 #define __LOG_LOG_ONCE_1(M) __LOG_LOG_4(__DEFAULT_LOGGER,Debug,M,true) 343 #define __LOG_TRACE_ONCE_2(I,M) __LOG_LOG_4(I,Trace,M,true) 344 #define __LOG_TRACE_ONCE_1(M) __LOG_LOG_4(__DEFAULT_LOGGER,Trace,M,true) 346 #define __LOG_DEBUG_ONCE_2(I,M) __LOG_LOG_4(I,Debug,M,true) 347 #define __LOG_DEBUG_ONCE_1(M) __LOG_LOG_4(__DEFAULT_LOGGER,Debug,M,true) 349 #define __LOG_INFO_ONCE_2(I,M) __LOG_LOG_4(I,Info,M,true) 350 #define __LOG_INFO_ONCE_1(M) __LOG_LOG_4(__DEFAULT_LOGGER,Info,M,true) 352 #define __LOG_PROG_ONCE_2(I,M) __LOG_LOG_4(I,Prog,M,true) 353 #define __LOG_PROG_ONCE_1(M) __LOG_LOG_4(__DEFAULT_LOGGER,Prog,M,true) 355 #define __LOG_WARN_ONCE_2(I,M) __LOG_LOG_4(I,Warn,M,true) 356 #define __LOG_WARN_ONCE_1(M) __LOG_LOG_4(__DEFAULT_LOGGER,Warn,M,true) 358 #define __LOG_ERROR_ONCE_2(I,M) __LOG_LOG_4(I,Error,M,true) 359 #define __LOG_ERROR_ONCE_1(M) __LOG_LOG_4(__DEFAULT_LOGGER,Error,M,true) 361 #define __LOG_FATAL_ONCE_2(I,M) __LOG_LOG_4(I,Fatal,M,true) 362 #define __LOG_FATAL_ONCE_1(M) __LOG_LOG_4(__DEFAULT_LOGGER,Fatal,M,true) 367 #define LOGGER(I,K) static scarab::logger I(K); 371 #define LOG(...) macro_dispatcher(__LOG_LOG_, __VA_ARGS__)(__VA_ARGS__) 376 #define LTRACE(...) macro_dispatcher(__LOG_TRACE_, __VA_ARGS__)(__VA_ARGS__) 377 #define LDEBUG(...) macro_dispatcher(__LOG_DEBUG_, __VA_ARGS__)(__VA_ARGS__) 379 #define LINFO(...) macro_dispatcher(__LOG_INFO_, __VA_ARGS__)(__VA_ARGS__) 380 #define LPROG(...) macro_dispatcher(__LOG_PROG_, __VA_ARGS__)(__VA_ARGS__) 381 #define LWARN(...) macro_dispatcher(__LOG_WARN_, __VA_ARGS__)(__VA_ARGS__) 382 #define LERROR(...) macro_dispatcher(__LOG_ERROR_, __VA_ARGS__)(__VA_ARGS__) 383 #define LFATAL(...) macro_dispatcher(__LOG_FATAL_, __VA_ARGS__)(__VA_ARGS__) 384 #define LASSERT(...) macro_dispatcher(__LOG_ASSERT_, __VA_ARGS__)(__VA_ARGS__) 386 #define LOG_ONCE(...) macro_dispatcher(__LOG_LOG_ONCE_, __VA_ARGS__)(__VA_ARGS__) 388 #define LTRACE_ONCE(...) 389 #define LDEBUG_ONCE(...) 391 #define LTRACE_ONCE(...) macro_dispatcher(__LOG_TRACE_ONCE_, __VA_ARGS__)(__VA_ARGS__) 392 #define LDEBUG_ONCE(...) macro_dispatcher(__LOG_DEBUG_ONCE_, __VA_ARGS__)(__VA_ARGS__) 394 #define LINFO_ONCE(...) macro_dispatcher(__LOG_INFO_ONCE_, __VA_ARGS__)(__VA_ARGS__) 395 #define LPROG_ONCE(...) macro_dispatcher(__LOG_PROG_ONCE_, __VA_ARGS__)(__VA_ARGS__) 396 #define LWARN_ONCE(...) macro_dispatcher(__LOG_WARN_ONCE_, __VA_ARGS__)(__VA_ARGS__) 397 #define LERROR_ONCE(...) macro_dispatcher(__LOG_ERROR_ONCE_, __VA_ARGS__)(__VA_ARGS__) 398 #define LFATAL_ONCE(...) macro_dispatcher(__LOG_FATAL_ONCE_, __VA_ARGS__)(__VA_ARGS__) 402 #define LOG(I, ...) __LOG_LOG_2(I, __VA_ARGS__) 404 #define LTRACE(I, ...) 405 #define LDEBUG(I, ...) 407 #define LTRACE(I, ...) __LOG_TRACE_2(I, __VA_ARGS__) 408 #define LDEBUG(I, ...) __LOG_DEBUG_2(I, __VA_ARGS__) 410 #define LINFO(I, ...) __LOG_INFO_2(I, __VA_ARGS__) 411 #define LPROG(I, ...) __LOG_PROG_2(I, __VA_ARGS__) 412 #define LWARN(I, ...) __LOG_WARN_2(I, __VA_ARGS__) 413 #define LERROR(I, ...) __LOG_ERROR_2(I, __VA_ARGS__) 414 #define LFATAL(I, ...) __LOG_FATAL_2(I, __VA_ARGS__) 415 #define LASSERT(I, ...) __LOG_ASSERT_2(I, __VA_ARGS__) 417 #define LOG_ONCE(I, ...) __LOG_LOG_ONCE_2(I, __VA_ARGS__) 419 #define LTRACE_ONCE(I, ...) 420 #define LDEBUG_ONCE(I, ...) 422 #define LTRACE_ONCE(I, ...) __LOG_TRACE_ONCE_2(I, __VA_ARGS__) 423 #define LDEBUG_ONCE(I, ...) __LOG_DEBUG_ONCE_2(I, __VA_ARGS__) 425 #define LINFO_ONCE(I, ...) __LOG_INFO_ONCE_2(I, __VA_ARGS__) 426 #define LPROG_ONCE(I, ...) __LOG_PROG_ONCE_2(I, __VA_ARGS__) 427 #define LWARN_ONCE(I, ...) __LOG_WARN_ONCE_2(I, __VA_ARGS__) 428 #define LERROR_ONCE(I, ...) __LOG_ERROR_ONCE_2(I, __VA_ARGS__) 429 #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)
void LogFatal(const std::string &message, const Location &loc=Location())
void LogError(const std::string &message, const Location &loc=Location())