--- os/log.c.old 2010-01-23 02:08:06.000000000 +0100 +++ os/log.c 2010-01-23 03:11:27.000000000 +0100 @@ -108,6 +108,8 @@ #endif static FILE *logFile = NULL; +static Bool logTimestamp = TRUE; +static Bool logFileTimestamp = TRUE; static Bool logFlush = FALSE; static Bool logSync = FALSE; static int logVerbosity = DEFAULT_LOG_VERBOSITY; @@ -257,7 +259,12 @@ LogVWrite(int verb, const char *f, va_list args) { static char tmpBuffer[1024]; + static char timestamp[21]; int len = 0; + size_t timestamp_len = 0; + Bool hasNewline = FALSE; + time_t t; + struct tm *tm; /* * Since a va_list can only be processed once, write the string to a @@ -267,12 +274,34 @@ if (verb < 0 || logFileVerbosity >= verb || logVerbosity >= verb) { vsnprintf(tmpBuffer, sizeof(tmpBuffer), f, args); len = strlen(tmpBuffer); + if (len == 0) + return; + } else { + return; } - if ((verb < 0 || logVerbosity >= verb) && len > 0) + if (logTimestamp || logFileTimestamp) { + t = time(NULL); + if (t != (time_t)-1) + tm = localtime(&t); + else + tm = NULL; + if (tm != NULL) + timestamp_len = strftime(timestamp, sizeof(timestamp), "%F %T ", tm); + } + hasNewline = (strchr(tmpBuffer, '\n') != NULL); + if ((verb < 0 || logVerbosity >= verb)) { + if (logTimestamp && timestamp_len) + fwrite(timestamp, timestamp_len, 1, stderr); + logTimestamp = hasNewline; fwrite(tmpBuffer, len, 1, stderr); - if ((verb < 0 || logFileVerbosity >= verb) && len > 0) { + } + if ((verb < 0 || logFileVerbosity >= verb)) { if (logFile) { + if (logFileTimestamp && timestamp_len) + fwrite(timestamp, timestamp_len, 1, logFile); + logFileTimestamp = hasNewline; fwrite(tmpBuffer, len, 1, logFile); + if (logFlush) { fflush(logFile); #ifndef WIN32