From b34f74bf038cfb4fbfe591a63f6b8f020a0d32ca Mon Sep 17 00:00:00 2001 From: Richard Cochran Date: Sun, 10 Jun 2012 12:27:59 +0200 Subject: [PATCH] Log the relative time rather than the process identification. When diagnosing a log file, it can be useful to know the relative time between the log entries. In contrast, the PID is mostly useless, since the program does not ever fork. Signed-off-by: Richard Cochran --- print.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/print.c b/print.c index 0ab1e6a..f42d254 100644 --- a/print.c +++ b/print.c @@ -18,8 +18,8 @@ */ #include #include -#include #include +#include #include #include "print.h" @@ -45,24 +45,26 @@ void print_verbose(void) void print(int level, char const *format, ...) { - pid_t pid; + struct timespec ts; va_list ap; char buf[1024]; if (level > print_level) return; - pid = getpid(); + clock_gettime(CLOCK_MONOTONIC, &ts); va_start(ap, format); vsnprintf(buf, sizeof(buf), format, ap); va_end(ap); if (verbose) { - fprintf(stdout, "ptp4l[%d]: %s\n", pid, buf); + fprintf(stdout, "ptp4l[%ld.%03ld]: %s\n", + ts.tv_sec, ts.tv_nsec / 1000000, buf); fflush(stdout); } if (use_syslog) { - syslog(level, "[%d] %s", pid, buf); + syslog(level, "[%ld.%03ld] %s", + ts.tv_sec, ts.tv_nsec / 1000000, buf); } }