* mu-log: add pid to log lines
This commit is contained in:
10
lib/mu-log.c
10
lib/mu-log.c
@ -255,22 +255,16 @@ log_write_fd (GLogLevelFlags level, const gchar *msg)
|
|||||||
/* truncate at 768-1 chars */
|
/* truncate at 768-1 chars */
|
||||||
char buf [768], timebuf [22];
|
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 */
|
/* get the time/date string */
|
||||||
now = time(NULL);
|
now = time(NULL);
|
||||||
strftime (timebuf, sizeof(timebuf), "%Y-%m-%d %H:%M:%S",
|
strftime (timebuf, sizeof(timebuf), "%Y-%m-%d %H:%M:%S",
|
||||||
localtime(&now));
|
localtime(&now));
|
||||||
|
|
||||||
/* now put it all together */
|
/* now put it all together */
|
||||||
len = snprintf (buf, sizeof(buf), "%s [%05u] %s: %s\n",
|
len = snprintf (buf, sizeof(buf), "%s [%s] %s\n", timebuf,
|
||||||
timebuf,
|
|
||||||
(unsigned)pid,
|
|
||||||
pfx(level), msg);
|
pfx(level), msg);
|
||||||
|
|
||||||
|
|
||||||
if (write (MU_LOG->_fd, buf, (size_t)len) < 0)
|
if (write (MU_LOG->_fd, buf, (size_t)len) < 0)
|
||||||
fprintf (stderr, "%s: failed to write to log: %s\n",
|
fprintf (stderr, "%s: failed to write to log: %s\n",
|
||||||
__FUNCTION__, strerror(errno));
|
__FUNCTION__, strerror(errno));
|
||||||
|
|||||||
Reference in New Issue
Block a user