mirror of https://github.com/djcb/mu.git
* mu-log: add pid to log lines
This commit is contained in:
parent
01f37d6b40
commit
d7ef2166a7
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 */
|
||||
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));
|
||||
|
|
Loading…
Reference in New Issue