* mu-log: add pid to log lines

This commit is contained in:
djcb 2012-09-20 21:24:49 +03:00
parent 01f37d6b40
commit d7ef2166a7
1 changed files with 2 additions and 8 deletions

View File

@ -255,22 +255,16 @@ 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 [%05u] %s: %s\n",
timebuf,
(unsigned)pid,
len = snprintf (buf, sizeof(buf), "%s [%s] %s\n", timebuf,
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));