mirror of
https://gitlab.uni-freiburg.de/opensourcevdi/spice
synced 2025-12-31 02:41:52 +00:00
spice: add [pid:tid] to log lines
This commit is contained in:
parent
18270e0235
commit
702b92cdb8
@ -24,6 +24,8 @@
|
||||
#include <log4cpp/Category.hh>
|
||||
#include <log4cpp/convenience.h>
|
||||
|
||||
#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__)
|
||||
|
||||
@ -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();
|
||||
|
||||
@ -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);
|
||||
|
||||
@ -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);
|
||||
|
||||
Loading…
Reference in New Issue
Block a user