diff --git a/src/debug.cpp b/src/debug.cpp index 5da1abc45..a68d8d71b 100644 --- a/src/debug.cpp +++ b/src/debug.cpp @@ -91,8 +91,7 @@ void log_msg(int level, const char *format, ...) #endif /* WIN32 */ va_list ap; - const char *color = ""; - const char *ending = "\033[0m"; + const char *color = NULL; switch (level) { case LOG_LEVEL_FATAL: color = "\033[1;31m"; break; @@ -101,12 +100,20 @@ void log_msg(int level, const char *format, ...) case LOG_LEVEL_NOTICE: color = "\033[0;32m"; break; } - char *format_new = (char *) alloca(strlen(format) + 4 + 7 + 1); - if (color_term) { + char *format_new = (char *) alloca(strlen(format) + 7 /* col start */ + 4 /* col end */ + + (3 + 20) /* time */ + 1); + if ((color_term && color) || log_level >= LOG_LEVEL_VERBOSE) { format_new[0] = '\0'; - strcat(format_new, color); + if (color_term && color) { + strcat(format_new, color); + } + if (log_level >= LOG_LEVEL_VERBOSE) { + sprintf(format_new + strlen(format_new), "[%ld] ", time(NULL)); + } strcat(format_new, format); - strcat(format_new, ending); + if (color_term && color) { + strcat(format_new, "\033[0m"); + } format = format_new; } diff --git a/src/debug.h b/src/debug.h index 4b5dc6ddf..64a9c0941 100644 --- a/src/debug.h +++ b/src/debug.h @@ -52,7 +52,8 @@ void debug_dump(void*lp, int len); #define error_msg(...) log_msg(LOG_LEVEL_ERROR, __VA_ARGS__) #define verbose_msg(...) log_msg(LOG_LEVEL_VERBOSE, __VA_ARGS__) -#define debug_msg(...) log_msg(LOG_LEVEL_DEBUG, "[pid/%d +%d %s] ", getpid(), __LINE__, __FILE__), log_msg(LOG_LEVEL_DEBUG, __VA_ARGS__) +///#define debug_msg(...) log_msg(LOG_LEVEL_DEBUG, "[pid/%d +%d %s] ", getpid(), __LINE__, __FILE__), log_msg(LOG_LEVEL_DEBUG, __VA_ARGS__) +#define debug_msg(...) log_msg(LOG_LEVEL_DEBUG, __VA_ARGS__) void log_msg(int log_level, const char *format, ...); #ifdef __cplusplus @@ -66,7 +67,7 @@ class Logger { public: inline Logger(int l) : level(l) {} - inline virtual ~Logger() { + inline ~Logger() { log_msg(level, os.str().c_str()); } inline std::ostringstream& Get() {