X-Git-Url: http://git.efficios.com/?p=babeltrace.git;a=blobdiff_plain;f=logging%2Flog.c;h=49a3061a11c95084b3376498a52f5c8f4f3b7753;hp=6d09e56b57beb2c0ca44a3a9adf310be31f1fb84;hb=f833fd0411f0c9c626d9bf79e57c3b0b681a34e7;hpb=beb0fb75663091c20765a8508162711ba828f456 diff --git a/logging/log.c b/logging/log.c index 6d09e56b..49a3061a 100644 --- a/logging/log.c +++ b/logging/log.c @@ -5,6 +5,12 @@ */ #include +#include +#include + +#ifdef __CYGWIN__ +extern unsigned long pthread_getsequence_np(pthread_t *); +#endif /* When defined, Android log (android/log.h) will be used by default instead of * stderr (ignored on non-Android platforms). Date, time, pid and tid (context) @@ -291,6 +297,9 @@ #include #include #include + +#define BT_LOG_OUTPUT_LEVEL dummy + #include #include @@ -301,6 +310,8 @@ #include #if defined(__linux__) #include + #elif (defined(__sun__) || defined(__CYGWIN__)) + /* Solaris and Cygwin have no sys/syslimits.h */ #else #include #endif @@ -731,7 +742,7 @@ static char lvl_char(const int lvl) #define TCACHE_FLUID (0x40000000 | 0x80000000) static unsigned g_tcache_mode = TCACHE_STALE; static struct timeval g_tcache_tv = {0, 0}; -static struct tm g_tcache_tm = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; +static struct tm g_tcache_tm = {0}; static INLINE int tcache_get(const struct timeval *const tv, struct tm *const tm) { @@ -819,6 +830,11 @@ static void pid_callback(int *const pid, int *const tid) #else #if defined(_WIN32) || defined(_WIN64) *tid = GetCurrentThreadId(); + #elif defined(__CYGWIN__) + pthread_t thr = pthread_self(); + *tid = (int)pthread_getsequence_np(&thr); + #elif defined(__sun__) + *tid = (int)pthread_self(); #elif defined(__ANDROID__) *tid = gettid(); #elif defined(__linux__) @@ -1250,6 +1266,31 @@ static void _bt_log_write_imp( msg.lvl = lvl; msg.tag = tag; g_buffer_cb(&msg, buf); + const char *rst_color_p = bt_common_color_reset(); + const char *rst_color_e = rst_color_p + strlen(rst_color_p); + const char *color_p = ""; + const char *color_e = color_p; + + switch (lvl) { + case BT_LOG_INFO: + color_p = bt_common_color_fg_blue(); + color_e = color_p + strlen(color_p); + break; + case BT_LOG_WARN: + color_p = bt_common_color_fg_yellow(); + color_e = color_p + strlen(color_p); + break; + case BT_LOG_ERROR: + case BT_LOG_FATAL: + color_p = bt_common_color_fg_red(); + color_e = color_p + strlen(color_p); + break; + default: + break; + } + + msg.p = put_stringn(color_p, color_e, msg.p, msg.e); + if (BT_LOG_PUT_CTX & mask) { put_ctx(&msg); @@ -1266,6 +1307,7 @@ static void _bt_log_write_imp( { put_msg(&msg, fmt, va); } + msg.p = put_stringn(rst_color_p, rst_color_e, msg.p, msg.e); log->output->callback(&msg, log->output->arg); if (0 != mem && BT_LOG_PUT_MSG & mask) {