This is the mail archive of the
libc-alpha@sourceware.org
mailing list for the glibc project.
Re: [patch] add timestamps to nscd debug logs
On 10/15/2009 10:35 AM, Ulrich Drepper wrote:
Jeffrey Bastian wrote:
It also uses the thread id instead of the process id on Linux systems.
That's bogus. For requests all the threads are the same and the ID
doesn't matter. For cleanup the threads are assigned their jobs at startup.
Okay, well, I just thought it might be interesting to log the thread id.
Here's an updated patch that just adds the timestamp.
Jeff
diff --git a/nscd/dbg_log.c b/nscd/dbg_log.c
index 5e192c9..2bd2340 100644
--- a/nscd/dbg_log.c
+++ b/nscd/dbg_log.c
@@ -20,6 +20,7 @@
#include <stdio.h>
#include <string.h>
#include <syslog.h>
+#include <time.h>
#include <unistd.h>
#include "dbg_log.h"
#include "nscd.h"
@@ -54,13 +55,20 @@ dbg_log (const char *fmt,...)
{
va_list ap;
char msg[512], msg2[512];
+ time_t rawtime;
+ struct tm now;
+ char datetime[32];
va_start (ap, fmt);
vsnprintf (msg2, sizeof (msg), fmt, ap);
if (debug_level > 0)
{
- snprintf (msg, sizeof (msg), "%d: %s%s", getpid (), msg2,
+ time (&rawtime);
+ localtime_r (&rawtime, &now);
+ strftime (datetime, 32, "%b %e %H:%M:%S", &now);
+
+ snprintf (msg, sizeof (msg), "%s %d: %s%s", datetime, getpid (), msg2,
msg2[strlen (msg2) - 1] == '\n' ? "" : "\n");
if (dbgout)
{