[PATCH] dix: adding timestamps to the server logs.
Bhaskar Tilak
btilak at nvidia.com
Tue Sep 1 01:44:27 PDT 2009
This patch prepends a timestamp to each line of the X log file.
Hopefully, this is helpful in diagnosing user problems, and correlating
between events in the X log and system log.
Here is an example snippet of the X log with timestamps prepended:
Aug 31 16:08:47 (II) Loading extension XFree86-VidModeExtension
Aug 31 16:08:47 (II) Loading extension DPMS
Aug 31 16:08:47 (II) Loading extension XVideo
Aug 31 16:08:47 (II) Loading extension XVideo-MotionCompensation
This patch enables timestamps by default, and provides a "-notimestamps"
commandline option to disable timestamps.
---
dix/globals.c | 5 +++++
doc/Xserver.man.pre | 4 ++++
include/globals.h | 1 +
os/log.c | 30 ++++++++++++++++++++++++------
os/utils.c | 5 +++++
5 files changed, 39 insertions(+), 6 deletions(-)
diff --git a/dix/globals.c b/dix/globals.c
index c24a94f..49a0819 100644
--- a/dix/globals.c
+++ b/dix/globals.c
@@ -139,3 +139,8 @@ char *ConnectionInfo;
CARD32 TimeOutValue = DEFAULT_TIMEOUT * MILLI_PER_SECOND;
DDXPointRec dixScreenOrigins[MAXSCREENS];
+
+/* Timestamping support for X logs. By default, timestamping in X logs is on.
+ * Use command line option '-notimestamps' to turn it off.
+ */
+Bool logTimestamps = TRUE;
diff --git a/doc/Xserver.man.pre b/doc/Xserver.man.pre
index 6154191..699fd15 100644
--- a/doc/Xserver.man.pre
+++ b/doc/Xserver.man.pre
@@ -197,6 +197,10 @@ overrides a previous
.B \-terminate
command line option.
.TP 8
+.B \-notimestamps
+Disable the time stamps in the X log file.
+By default, the server adds the time stamps to the X log file.
+.TP 8
.B \-p \fIminutes\fP
sets screen-saver pattern cycle time in minutes.
.TP 8
diff --git a/include/globals.h b/include/globals.h
index 52c19a4..779f994 100644
--- a/include/globals.h
+++ b/include/globals.h
@@ -26,6 +26,7 @@ extern _X_EXPORT Bool noTestExtensions;
extern _X_EXPORT DDXPointRec dixScreenOrigins[MAXSCREENS];
extern _X_EXPORT char *ConnectionInfo;
+extern _X_EXPORT Bool logTimestamps;
#ifdef DPMSExtension
extern _X_EXPORT CARD32 DPMSStandbyTime;
diff --git a/os/log.c b/os/log.c
index 8108890..47364bb 100644
--- a/os/log.c
+++ b/os/log.c
@@ -316,7 +316,10 @@ void
LogVMessageVerb(MessageType type, int verb, const char *format, va_list args)
{
const char *s = X_UNKNOWN_STRING;
- char tmpBuf[1024];
+ char tmpBuf[1024], timestampBuf[32];
+ time_t rawtime;
+ struct tm *timeinfo = NULL;
+ int timeFault = 0;
/* Ignore verbosity for X_ERROR */
if (logVerbosity >= verb || logFileVerbosity >= verb || type == X_ERROR) {
@@ -358,11 +361,26 @@ LogVMessageVerb(MessageType type, int verb, const char *format, va_list args)
break;
}
- /* if s is not NULL we need a space before format */
- snprintf(tmpBuf, sizeof(tmpBuf), "%s%s%s", s ? s : "",
- s ? " " : "",
- format);
- LogVWrite(verb, tmpBuf, args);
+ if (!logTimestamps || (-1 == time(&rawtime))) {
+ timeFault = 1;
+ } else {
+ if (NULL == (timeinfo = localtime(&rawtime)))
+ timeFault = 1;
+ }
+
+ if (timeFault || !strftime(timestampBuf, sizeof(timestampBuf),
+ "%b %d %X ", timeinfo))
+ timestampBuf[0] = '\0';
+
+ /* being extra cautious with string management */
+ timestampBuf[31] = '\0';
+
+ /* if s is not NULL we need a space before format */
+ snprintf(tmpBuf, sizeof(tmpBuf), "%s%s%s%s", timestampBuf,
+ s ? s : "",
+ s ? " " : "",
+ format);
+ LogVWrite(verb, tmpBuf, args);
}
}
diff --git a/os/utils.c b/os/utils.c
index 3718b17..eeb9781 100644
--- a/os/utils.c
+++ b/os/utils.c
@@ -511,6 +511,7 @@ void UseMsg(void)
ErrorF("-logo enable logo in screen saver\n");
ErrorF("nologo disable logo in screen saver\n");
#endif
+ ErrorF("-notimestamps disable the timestamps in X log file\n");
ErrorF("-nolisten string don't listen on protocol\n");
ErrorF("-noreset don't reset after last client exists\n");
ErrorF("-reset reset after last client exists\n");
@@ -960,6 +961,10 @@ ProcessCommandLine(int argc, char *argv[])
else
UseMsg();
}
+ else if ( strcmp( argv[i], "-notimestamps") == 0)
+ {
+ logTimestamps = FALSE;
+ }
else
{
ErrorF("Unrecognized option: %s\n", argv[i]);
--
1.5.4.5
[nvpublic]
More information about the xorg-devel
mailing list