Port: Add Solaris tid support to logging
[babeltrace.git] / logging / log.c
index 4bd5014d9f1ed0016cf218d73e1df7f608f6f971..4561012984e75eb6548a78573e4d597683c1a305 100644 (file)
@@ -5,6 +5,12 @@
  */
 
 #include <babeltrace/babeltrace-internal.h>
+#include <babeltrace/common-internal.h>
+#include <pthread.h>
+
+#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)
@@ -822,6 +828,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__)
@@ -1253,6 +1264,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);
@@ -1269,6 +1305,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)
        {
This page took 0.025518 seconds and 4 git commands to generate.