summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBent Bisballe Nyeng <deva@aasimon.org>2012-02-23 10:41:46 +0100
committerBent Bisballe Nyeng <deva@aasimon.org>2012-02-23 10:41:46 +0100
commit2f951a372c5330b4e8a8209122905e073d189bda (patch)
tree2a59883da12beb5db91fd33234698cc07dc50ec6
parentddd6826b161e2bb7735b152c15c9ba9bab79aa29 (diff)
Add thread id to debug output.
-rw-r--r--server/src/debug.cc21
1 files changed, 15 insertions, 6 deletions
diff --git a/server/src/debug.cc b/server/src/debug.cc
index fa83a80..d3e74e8 100644
--- a/server/src/debug.cc
+++ b/server/src/debug.cc
@@ -34,6 +34,13 @@
#include "log.h"
+#include <pthread.h>
+
+static unsigned int gettid()
+{
+ return (unsigned int)pthread_self();
+}
+
static FILE *logfp = stderr;
#define NELEM(x) (sizeof(x)/sizeof((x)[0]))
@@ -72,8 +79,8 @@ int __debug(const char *func, const int line,
int ret = 0;
if(__debug_enabled(cl, ch)) {
if((unsigned)cl < NELEM(debug_class_str))
- ret += fprintf(logfp, "%s:%s:%s:%d ",
- debug_class_str[(unsigned)cl], ch, func, line);
+ ret += fprintf(logfp, "%u %s:%s:%s:%d ",
+ gettid(), debug_class_str[(unsigned)cl], ch, func, line);
if(fmt) {
va_list va;
va_start(va, fmt);
@@ -94,8 +101,8 @@ int __debug_va(const char *func, const int line,
int ret = 0;
if(__debug_enabled(cl, ch)) {
if((unsigned)cl < NELEM(debug_class_str))
- ret += fprintf(logfp, "%s:%s:%s:%d ",
- debug_class_str[(unsigned)cl], ch, func, line);
+ ret += fprintf(logfp, "%u %s:%s:%s:%d ",
+ gettid(), debug_class_str[(unsigned)cl], ch, func, line);
if(fmt)
ret += vfprintf(logfp, fmt, va);
}
@@ -120,7 +127,8 @@ int __log(const char *func, const int line, const enum __debug_class cl,
if((unsigned)cl < NELEM(debug_class_str))
if((unsigned)cl < NELEM(debug_class_str))
#ifdef WITH_DEBUG
- ret = fprintf(logfp, "%s:%s:%s:%d ", debug_class_str[(unsigned)cl], ch, func, line);
+ ret = fprintf(logfp, "%u %s:%s:%s:%d ",
+ gettid(), debug_class_str[(unsigned)cl], ch, func, line);
#endif
sprintf(str, "%d", line);
logmsg = std::string(debug_class_str[(unsigned)cl]) + ":" + ch + ":" + func + ":" + str;
@@ -157,7 +165,8 @@ int __log_va(const char *func, const int line, const enum __debug_class cl,
if(__debug_enabled(cl, ch)) {
if((unsigned)cl < NELEM(debug_class_str))
#ifdef WITH_DEBUG
- ret = fprintf(logfp, "%s:%s:%s:%d ", debug_class_str[(unsigned)cl], ch, func, line);
+ ret = fprintf(logfp, "%u %s:%s:%s:%d ",
+ gettid(), debug_class_str[(unsigned)cl], ch, func, line);
#endif
sprintf(str, "%d", line);
logmsg = std::string(debug_class_str[(unsigned)cl]) + ":" + ch + ":" + func + ":" + str;