From 01f37d6b4098df8b802c6849e8c2a5d2cad6ead9 Mon Sep 17 00:00:00 2001 From: djcb Date: Thu, 20 Sep 2012 21:24:03 +0300 Subject: [PATCH] mu-log: add pid to log lines --- lib/mu-log.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/lib/mu-log.c b/lib/mu-log.c index b9d4117c..1691ea2f 100644 --- a/lib/mu-log.c +++ b/lib/mu-log.c @@ -255,16 +255,22 @@ log_write_fd (GLogLevelFlags level, const gchar *msg) /* truncate at 768-1 chars */ char buf [768], timebuf [22]; + /* get the process id, once. */ + static pid_t pid = 0; + if (G_UNLIKELY(pid == 0)) + pid = getpid(); + /* get the time/date string */ now = time(NULL); strftime (timebuf, sizeof(timebuf), "%Y-%m-%d %H:%M:%S", localtime(&now)); /* now put it all together */ - len = snprintf (buf, sizeof(buf), "%s [%s] %s\n", timebuf, + len = snprintf (buf, sizeof(buf), "%s [%05u] %s: %s\n", + timebuf, + (unsigned)pid, pfx(level), msg); - if (write (MU_LOG->_fd, buf, (size_t)len) < 0) fprintf (stderr, "%s: failed to write to log: %s\n", __FUNCTION__, strerror(errno));