[gjs: 3/5] log: Allow logging thread ID of each message
- From: Cosimo Cecchi <cosimoc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gjs: 3/5] log: Allow logging thread ID of each message
- Date: Mon, 19 Feb 2018 04:42:37 +0000 (UTC)
commit 37588badeb4b5333fd184933f74d4805cea46c1d
Author: Philip Chimento <philip chimento gmail com>
Date: Sat Feb 17 23:20:23 2018 -0800
log: Allow logging thread ID of each message
In order to help debug race conditions, we add the GJS_DEBUG_THREAD
environment variable, which will prefix each debug log message with the
thread ID according to g_thread_self().
util/log.cpp | 13 +++++++++++++
1 file changed, 13 insertions(+)
---
diff --git a/util/log.cpp b/util/log.cpp
index afd3aa1..39fae4a 100644
--- a/util/log.cpp
+++ b/util/log.cpp
@@ -101,6 +101,8 @@ gjs_debug(GjsDebugTopic topic,
static bool debug_log_enabled = false;
static bool checked_for_timestamp = false;
static bool print_timestamp = false;
+ static bool checked_for_thread = false;
+ static bool print_thread = false;
static GTimer *timer = NULL;
const char *prefix;
va_list args;
@@ -111,6 +113,11 @@ gjs_debug(GjsDebugTopic topic,
checked_for_timestamp = true;
}
+ if (!checked_for_thread) {
+ print_thread = gjs_environment_variable_is_set("GJS_DEBUG_THREAD");
+ checked_for_thread = true;
+ }
+
if (print_timestamp && !timer) {
timer = g_timer_new();
}
@@ -275,6 +282,12 @@ _Pragma("GCC diagnostic pop")
previous = total;
}
+ if (print_thread) {
+ char *s2 = g_strdup_printf("(thread %p) %s", g_thread_self(), s);
+ g_free(s);
+ s = s2;
+ }
+
write_to_stream(logfp, prefix, s);
g_free(s);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]