[PATCH 03/10] Add timestamping to logging functions

Julien Cristau jcristau at debian.org
Tue Jan 5 10:18:17 PST 2010


Based on patch by Branden Robinson <branden at debian.org>
---
 error.c |   20 +++++++++++++++++---
 1 files changed, 17 insertions(+), 3 deletions(-)

diff --git a/error.c b/error.c
index d1bd16e..4f5eb6b 100644
--- a/error.c
+++ b/error.c
@@ -64,9 +64,6 @@ LogVWrite(const char *fmt, va_list args)
 	va_end(args);		\
     } while(0)
 
-#define LogHeader(type)		\
-    LogAppend("xdm %s (pid %ld): ", type, (long)getpid())
-
 /* Append more text to the log without a new header, right after
    having called LogInfo or LogError */
 void
@@ -75,6 +72,23 @@ LogAppend(const char * fmt, ...)
     LogVarArgsWrite(fmt);
 }
 
+static void
+LogHeader(const char *type) {
+    time_t seconds;
+    size_t rc = 0;
+    struct tm *timestamp = NULL;
+    char timebuf[256];
+    if (time(&seconds) != (time_t) -1)
+	timestamp = localtime(&seconds);
+
+    if (timestamp)
+	rc = strftime(timebuf, 255, "%c", timestamp);
+    if (!rc)
+	strcpy(timebuf, "(time unavailable)");
+
+    LogAppend("%s xdm %s (pid %ld): ", timebuf, type, (long)getpid());
+}
+
 void
 LogInfo(const char * fmt, ...)
 {
-- 
1.6.5.7



More information about the xorg-devel mailing list