diff options
author | Egor Tensin <Egor.Tensin@gmail.com> | 2023-06-12 01:32:43 +0200 |
---|---|---|
committer | Egor Tensin <Egor.Tensin@gmail.com> | 2023-06-12 01:42:34 +0200 |
commit | 9f09e9676d2f95b6ab2c5b7a5c0c64888e4df6b3 (patch) | |
tree | 388452a84f3a6e4f2308a39e2649ee54481dbf22 /src | |
parent | command: fix a race condition (diff) | |
download | cimple-9f09e9676d2f95b6ab2c5b7a5c0c64888e4df6b3.tar.gz cimple-9f09e9676d2f95b6ab2c5b7a5c0c64888e4df6b3.zip |
log: prefix with thread ID
Diffstat (limited to '')
-rw-r--r-- | src/log.h | 11 |
1 files changed, 9 insertions, 2 deletions
@@ -14,6 +14,7 @@ #include <stdio.h> #include <sys/time.h> #include <time.h> +#include <unistd.h> 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() \ |