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 ";" 131 Location(
const char*
const fileName =
"",
const char*
const functionName =
"",
int lineNumber = -1) :
132 fLineNumber(lineNumber), fFileName(fileName), fFunctionName(functionName)
150 logger(
const char* name = 0);
152 logger(
const std::string& name);
161 bool IsLevelEnabled(
ELevel level)
const;
167 void SetLevel(
ELevel level)
const;
173 void SetGlobalLevel(
ELevel level)
const;
179 static void SetColored(
bool flag);
185 static void SetOutStream(std::ostream* stream);
191 static void SetErrStream(std::ostream* stream);
210 Log(eTrace, message, loc);
220 Log(eDebug, message, loc);
230 Log(eInfo, message, loc);
240 Log(eProg, message, loc);
250 Log(eWarn, message, loc);
260 Log(eError, message, loc);
270 Log(eFatal, message, loc);
282 #define __DEFAULT_LOGGER scarab::logger::GetRootLogger() 284 #define __LOG_LOCATION scarab::logger::Location(__FILE__, __FUNC__, __LINE__) 285 #define __LOG_LOG_4(I,L,M,O) \ 287 if (I.IsLevelEnabled(scarab::logger::e##L)) { \ 288 static bool _sLoggerMarker = false; \ 289 if (!O || !_sLoggerMarker) { \ 290 _sLoggerMarker = true; \ 291 std::ostringstream stream; stream << M; \ 292 I.Log(scarab::logger::e##L, stream.str(), __LOG_LOCATION); \ 298 #define __LOG_LOG_3(I,L,M) __LOG_LOG_4(I,L,M,false) 299 #define __LOG_LOG_2(L,M) __LOG_LOG_4(__DEFAULT_LOGGER,L,M,false) 300 #define __LOG_LOG_1(M) __LOG_LOG_4(__DEFAULT_LOGGER,Debug,M,false) 302 #define __LOG_TRACE_2(I,M) __LOG_LOG_4(I,Trace,M,false) 303 #define __LOG_TRACE_1(M) __LOG_LOG_4(__DEFAULT_LOGGER,Trace,M,false) 305 #define __LOG_DEBUG_2(I,M) __LOG_LOG_4(I,Debug,M,false) 306 #define __LOG_DEBUG_1(M) __LOG_LOG_4(__DEFAULT_LOGGER,Debug,M,false) 308 #define __LOG_INFO_2(I,M) __LOG_LOG_4(I,Info,M,false) 309 #define __LOG_INFO_1(M) __LOG_LOG_4(__DEFAULT_LOGGER,Info,M,false) 311 #define __LOG_PROG_2(I,M) __LOG_LOG_4(I,Prog,M,false) 312 #define __LOG_PROG_1(M) __LOG_LOG_4(__DEFAULT_LOGGER,Prog,M,false) 314 #define __LOG_WARN_2(I,M) __LOG_LOG_4(I,Warn,M,false) 315 #define __LOG_WARN_1(M) __LOG_LOG_4(__DEFAULT_LOGGER,Warn,M,false) 317 #define __LOG_ERROR_2(I,M) __LOG_LOG_4(I,Error,M,false) 318 #define __LOG_ERROR_1(M) __LOG_LOG_4(__DEFAULT_LOGGER,Error,M,false) 320 #define __LOG_FATAL_2(I,M) __LOG_LOG_4(I,Fatal,M,false) 321 #define __LOG_FATAL_1(M) __LOG_LOG_4(__DEFAULT_LOGGER,Fatal,M,false) 323 #define __LOG_ASSERT_3(I,C,M) if (!(C)) { __LOG_ERROR_2(I,M) } 324 #define __LOG_ASSERT_2(C,M) __LOG_ASSERT_3(__DEFAULT_LOGGER,C,M) 327 #define __LOG_LOG_ONCE_3(I,L,M) __LOG_LOG_4(I,L,M,true) 328 #define __LOG_LOG_ONCE_2(L,M) __LOG_LOG_4(__DEFAULT_LOGGER,L,M,true) 329 #define __LOG_LOG_ONCE_1(M) __LOG_LOG_4(__DEFAULT_LOGGER,Debug,M,true) 331 #define __LOG_TRACE_ONCE_2(I,M) __LOG_LOG_4(I,Trace,M,true) 332 #define __LOG_TRACE_ONCE_1(M) __LOG_LOG_4(__DEFAULT_LOGGER,Trace,M,true) 334 #define __LOG_DEBUG_ONCE_2(I,M) __LOG_LOG_4(I,Debug,M,true) 335 #define __LOG_DEBUG_ONCE_1(M) __LOG_LOG_4(__DEFAULT_LOGGER,Debug,M,true) 337 #define __LOG_INFO_ONCE_2(I,M) __LOG_LOG_4(I,Info,M,true) 338 #define __LOG_INFO_ONCE_1(M) __LOG_LOG_4(__DEFAULT_LOGGER,Info,M,true) 340 #define __LOG_PROG_ONCE_2(I,M) __LOG_LOG_4(I,Prog,M,true) 341 #define __LOG_PROG_ONCE_1(M) __LOG_LOG_4(__DEFAULT_LOGGER,Prog,M,true) 343 #define __LOG_WARN_ONCE_2(I,M) __LOG_LOG_4(I,Warn,M,true) 344 #define __LOG_WARN_ONCE_1(M) __LOG_LOG_4(__DEFAULT_LOGGER,Warn,M,true) 346 #define __LOG_ERROR_ONCE_2(I,M) __LOG_LOG_4(I,Error,M,true) 347 #define __LOG_ERROR_ONCE_1(M) __LOG_LOG_4(__DEFAULT_LOGGER,Error,M,true) 349 #define __LOG_FATAL_ONCE_2(I,M) __LOG_LOG_4(I,Fatal,M,true) 350 #define __LOG_FATAL_ONCE_1(M) __LOG_LOG_4(__DEFAULT_LOGGER,Fatal,M,true) 355 #define LOGGER(I,K) static scarab::logger I(K); 359 #define LOG(...) macro_dispatcher(__LOG_LOG_, __VA_ARGS__)(__VA_ARGS__) 364 #define LTRACE(...) macro_dispatcher(__LOG_TRACE_, __VA_ARGS__)(__VA_ARGS__) 365 #define LDEBUG(...) macro_dispatcher(__LOG_DEBUG_, __VA_ARGS__)(__VA_ARGS__) 367 #define LINFO(...) macro_dispatcher(__LOG_INFO_, __VA_ARGS__)(__VA_ARGS__) 368 #define LPROG(...) macro_dispatcher(__LOG_PROG_, __VA_ARGS__)(__VA_ARGS__) 369 #define LWARN(...) macro_dispatcher(__LOG_WARN_, __VA_ARGS__)(__VA_ARGS__) 370 #define LERROR(...) macro_dispatcher(__LOG_ERROR_, __VA_ARGS__)(__VA_ARGS__) 371 #define LFATAL(...) macro_dispatcher(__LOG_FATAL_, __VA_ARGS__)(__VA_ARGS__) 372 #define LASSERT(...) macro_dispatcher(__LOG_ASSERT_, __VA_ARGS__)(__VA_ARGS__) 374 #define LOG_ONCE(...) macro_dispatcher(__LOG_LOG_ONCE_, __VA_ARGS__)(__VA_ARGS__) 376 #define LTRACE_ONCE(...) 377 #define LDEBUG_ONCE(...) 379 #define LTRACE_ONCE(...) macro_dispatcher(__LOG_TRACE_ONCE_, __VA_ARGS__)(__VA_ARGS__) 380 #define LDEBUG_ONCE(...) macro_dispatcher(__LOG_DEBUG_ONCE_, __VA_ARGS__)(__VA_ARGS__) 382 #define LINFO_ONCE(...) macro_dispatcher(__LOG_INFO_ONCE_, __VA_ARGS__)(__VA_ARGS__) 383 #define LPROG_ONCE(...) macro_dispatcher(__LOG_PROG_ONCE_, __VA_ARGS__)(__VA_ARGS__) 384 #define LWARN_ONCE(...) macro_dispatcher(__LOG_WARN_ONCE_, __VA_ARGS__)(__VA_ARGS__) 385 #define LERROR_ONCE(...) macro_dispatcher(__LOG_ERROR_ONCE_, __VA_ARGS__)(__VA_ARGS__) 386 #define LFATAL_ONCE(...) macro_dispatcher(__LOG_FATAL_ONCE_, __VA_ARGS__)(__VA_ARGS__) 390 #define LOG(I, ...) __LOG_LOG_2(I, __VA_ARGS__) 392 #define LTRACE(I, ...) 393 #define LDEBUG(I, ...) 395 #define LTRACE(I, ...) __LOG_TRACE_2(I, __VA_ARGS__) 396 #define LDEBUG(I, ...) __LOG_DEBUG_2(I, __VA_ARGS__) 398 #define LINFO(I, ...) __LOG_INFO_2(I, __VA_ARGS__) 399 #define LPROG(I, ...) __LOG_PROG_2(I, __VA_ARGS__) 400 #define LWARN(I, ...) __LOG_WARN_2(I, __VA_ARGS__) 401 #define LERROR(I, ...) __LOG_ERROR_2(I, __VA_ARGS__) 402 #define LFATAL(I, ...) __LOG_FATAL_2(I, __VA_ARGS__) 403 #define LASSERT(I, ...) __LOG_ASSERT_2(I, __VA_ARGS__) 405 #define LOG_ONCE(I, ...) __LOG_LOG_ONCE_2(I, __VA_ARGS__) 407 #define LTRACE_ONCE(I, ...) 408 #define LDEBUG_ONCE(I, ...) 410 #define LTRACE_ONCE(I, ...) __LOG_TRACE_ONCE_2(I, __VA_ARGS__) 411 #define LDEBUG_ONCE(I, ...) __LOG_DEBUG_ONCE_2(I, __VA_ARGS__) 413 #define LINFO_ONCE(I, ...) __LOG_INFO_ONCE_2(I, __VA_ARGS__) 414 #define LPROG_ONCE(I, ...) __LOG_PROG_ONCE_2(I, __VA_ARGS__) 415 #define LWARN_ONCE(I, ...) __LOG_WARN_ONCE_2(I, __VA_ARGS__) 416 #define LERROR_ONCE(I, ...) __LOG_ERROR_ONCE_2(I, __VA_ARGS__) 417 #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())