From 702b92cdb80eac8fd3b5da3a96bfcfa622f7c7af Mon Sep 17 00:00:00 2001 From: Arnon Gilboa Date: Tue, 17 Nov 2009 16:47:41 +0200 Subject: spice: add [pid:tid] to log lines --- client/debug.h | 11 +++++++---- client/platform.h | 2 ++ client/windows/platform.cpp | 11 +++++++++++ client/x11/platform.cpp | 11 +++++++++++ 4 files changed, 31 insertions(+), 4 deletions(-) diff --git a/client/debug.h b/client/debug.h index cf84296c..1c6f6a42 100644 --- a/client/debug.h +++ b/client/debug.h @@ -24,6 +24,8 @@ #include #include +#include "platform.h" + #ifdef WIN32 #define snprintf _snprintf #endif @@ -74,10 +76,11 @@ static inline std::string pretty_func_to_func_name(const std::string& f_name) LOG4CPP_LOGGER("spice") -#define LOG(type, format, ...) { \ - std::string log_message; \ - string_printf(log_message, "%s: " format, FUNC_NAME, ## __VA_ARGS__); \ - LOG4CPP_##type(logger, log_message.c_str()); \ +#define LOG(type, format, ...) { \ + std::string log_message; \ + string_printf(log_message, "[%llu:%llu] %s: " format, Platform::get_process_id(), \ + Platform::get_thread_id(), FUNC_NAME, ## __VA_ARGS__); \ + LOG4CPP_##type(logger, log_message.c_str()); \ } #define LOG_INFO(format, ...) LOG(INFO, format, ## __VA_ARGS__) diff --git a/client/platform.h b/client/platform.h index ece61c9d..c32b8634 100644 --- a/client/platform.h +++ b/client/platform.h @@ -38,6 +38,8 @@ public: static void yield(); static uint64_t get_monolithic_time(); static void get_temp_dir(std::string& path); + static uint64_t get_process_id(); + static uint64_t get_thread_id(); static const MonitorsList& init_monitors(); static void destroy_monitors(); diff --git a/client/windows/platform.cpp b/client/windows/platform.cpp index 6b218404..6d5deba5 100644 --- a/client/windows/platform.cpp +++ b/client/windows/platform.cpp @@ -207,6 +207,17 @@ void Platform::get_temp_dir(std::string& path) delete[] tmp_path; } +uint64_t Platform::get_process_id() +{ + static uint64_t pid = GetCurrentProcessId(); + return pid; +} + +uint64_t Platform::get_thread_id() +{ + return GetCurrentThreadId(); +} + class WinMonitor: public Monitor { public: WinMonitor(int id, const wchar_t* name, const wchar_t* string); diff --git a/client/x11/platform.cpp b/client/x11/platform.cpp index 10d621ba..217664a4 100644 --- a/client/x11/platform.cpp +++ b/client/x11/platform.cpp @@ -223,6 +223,17 @@ void Platform::get_temp_dir(std::string& path) path = "/tmp/"; } +uint64_t Platform::get_process_id() +{ + static uint64_t pid = uint64_t(getpid()); + return pid; +} + +uint64_t Platform::get_thread_id() +{ + return uint64_t(syscall(SYS_gettid)); +} + void Platform::msleep(unsigned int millisec) { usleep(millisec * 1000); -- cgit