From 9f09e9676d2f95b6ab2c5b7a5c0c64888e4df6b3 Mon Sep 17 00:00:00 2001 From: Egor Tensin Date: Mon, 12 Jun 2023 01:32:43 +0200 Subject: log: prefix with thread ID --- src/log.h | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/log.h b/src/log.h index a0213ee..9b0c945 100644 --- a/src/log.h +++ b/src/log.h @@ -14,6 +14,7 @@ #include #include #include +#include static inline void log_print_timestamp(FILE *dest) { @@ -28,17 +29,23 @@ static inline void log_print_timestamp(FILE *dest) return; buf[0] = '\0'; - used += strftime(buf + used, sizeof(buf) - used, "[%F %T", &tm); - used += snprintf(buf + used, sizeof(buf) - used, ".%03ld] ", tv.tv_usec / 1000); + used += strftime(buf + used, sizeof(buf) - used, "%F %T", &tm); + used += snprintf(buf + used, sizeof(buf) - used, ".%03ld | ", tv.tv_usec / 1000); fprintf(dest, "%s", buf); } +static inline void log_print_thread_id(FILE *dest) +{ + fprintf(dest, "%d | ", gettid()); +} + #define CONCAT_INNER(a, b) a##b #define CONCAT(a, b) CONCAT_INNER(a, b) static inline void log_prefix(FILE *dest) { log_print_timestamp(dest); + log_print_thread_id(dest); } #define log_err_prefix() \ -- cgit v1.2.3