From 7e14c2f63c89fe615393387c36adfb4f48d48240 Mon Sep 17 00:00:00 2001 From: Jon TURNEY Date: Tue, 21 Jul 2009 16:57:07 +0100 Subject: [PATCH 2/2] Cygwin/X: Add a timestamp to log messages Add a timestamp to log messages Also tidy up some cosmetic issue in log strings: - Add a missing '\n' - Fix some strings starting with '\n' - Remove '\f' from some log strings --- dix/registry.c | 2 +- hw/xwin/winclipboardthread.c | 2 +- hw/xwin/winmultiwindowwm.c | 8 ++++---- hw/xwin/winshadddnl.c | 2 +- os/log.c | 28 +++++++++++++++++++++++++++- 5 files changed, 34 insertions(+), 8 deletions(-) diff --git a/dix/registry.c b/dix/registry.c index a519cff..0135ad2 100644 --- a/dix/registry.c +++ b/dix/registry.c @@ -313,7 +313,7 @@ dixResetRegistry(void) fclose(fh); fh = fopen(FILENAME, "r"); if (!fh) - LogMessage(X_WARNING, "Failed to open protocol names file " FILENAME); + LogMessage(X_WARNING, "Failed to open protocol names file " FILENAME "\n"); /* Add built-in resources */ RegisterResourceName(RT_NONE, "NONE"); diff --git a/hw/xwin/winclipboardthread.c b/hw/xwin/winclipboardthread.c index 3b81e90..fbedcc3 100644 --- a/hw/xwin/winclipboardthread.c +++ b/hw/xwin/winclipboardthread.c @@ -454,7 +454,7 @@ winClipboardErrorHandler (Display *pDisplay, XErrorEvent *pErr) static int winClipboardIOErrorHandler (Display *pDisplay) { - ErrorF ("\nwinClipboardIOErrorHandler!\n\n"); + ErrorF ("winClipboardIOErrorHandler!\n\n"); /* Restart at the main entry point */ longjmp (g_jmpEntry, WIN_JMP_ERROR_IO); diff --git a/hw/xwin/winmultiwindowwm.c b/hw/xwin/winmultiwindowwm.c index df5832b..703b171 100644 --- a/hw/xwin/winmultiwindowwm.c +++ b/hw/xwin/winmultiwindowwm.c @@ -938,7 +938,7 @@ winMultiWindowXMsgProc (void *pArg) if (pProcArg->pDisplay == NULL) { ErrorF ("winMultiWindowXMsgProc - Could not open display, try: %d, " - "sleeping: %d\n\f", + "sleeping: %d\n", iRetries + 1, WIN_CONNECT_DELAY); ++iRetries; sleep (WIN_CONNECT_DELAY); @@ -1301,7 +1301,7 @@ winInitMultiWindowWM (WMInfoPtr pWMInfo, WMProcArgPtr pProcArg) if (pWMInfo->pDisplay == NULL) { ErrorF ("winInitMultiWindowWM - Could not open display, try: %d, " - "sleeping: %d\n\f", + "sleeping: %d\n", iRetries + 1, WIN_CONNECT_DELAY); ++iRetries; sleep (WIN_CONNECT_DELAY); @@ -1404,7 +1404,7 @@ winMultiWindowWMErrorHandler (Display *pDisplay, XErrorEvent *pErr) static int winMultiWindowWMIOErrorHandler (Display *pDisplay) { - ErrorF ("\nwinMultiWindowWMIOErrorHandler!\n\n"); + ErrorF ("winMultiWindowWMIOErrorHandler!\n\n"); if (g_shutdown) pthread_exit(NULL); @@ -1444,7 +1444,7 @@ winMultiWindowXMsgProcErrorHandler (Display *pDisplay, XErrorEvent *pErr) static int winMultiWindowXMsgProcIOErrorHandler (Display *pDisplay) { - ErrorF ("\nwinMultiWindowXMsgProcIOErrorHandler!\n\n"); + ErrorF ("winMultiWindowXMsgProcIOErrorHandler!\n\n"); /* Restart at the main entry point */ longjmp (g_jmpXMsgProcEntry, WIN_JMP_ERROR_IO); diff --git a/hw/xwin/winshadddnl.c b/hw/xwin/winshadddnl.c index e319c8e..b9f169d 100644 --- a/hw/xwin/winshadddnl.c +++ b/hw/xwin/winshadddnl.c @@ -554,7 +554,7 @@ winFinishCreateWindowsWindowDDNL (WindowPtr pWin) int iWidth, iHeight; int iX, iY; - winDebug ("\nwinFinishCreateWindowsWindowDDNL!\n\n"); + winDebug ("winFinishCreateWindowsWindowDDNL!\n\n"); iX = pWin->drawable.x + GetSystemMetrics (SM_XVIRTUALSCREEN); iY = pWin->drawable.y + GetSystemMetrics (SM_YVIRTUALSCREEN); diff --git a/os/log.c b/os/log.c index 692e78a..67c2069 100644 --- a/os/log.c +++ b/os/log.c @@ -268,7 +268,33 @@ LogVWrite(int verb, const char *f, va_list args) fwrite(tmpBuffer, len, 1, stderr); if ((verb < 0 || logFileVerbosity >= verb) && len > 0) { if (logFile) { - fwrite(tmpBuffer, len, 1, logFile); + static char tmpBuffer2[1024]; + static Bool needTimestamp = TRUE; + + if (needTimestamp) + { + needTimestamp = FALSE; + + /* Format the date and time per ISO8601 */ + time_t t = time(NULL); + struct tm tm; + localtime_r(&t, &tm); + strftime(tmpBuffer2, sizeof(tmpBuffer2), "%F %T ", &tm); + + /* Concatente the string produced by formatting the va_list */ + strncat(tmpBuffer2, tmpBuffer, sizeof(tmpBuffer2)); + } + else + { + strncpy(tmpBuffer2, tmpBuffer, sizeof(tmpBuffer2)); + } + len = strlen(tmpBuffer2); + + /* If the log message ends with a newline, note that we need to start the next line with a timestamp */ + if (tmpBuffer2[len-1] == '\n') + needTimestamp = TRUE; + + fwrite(tmpBuffer2, len, 1, logFile); if (logFlush) { fflush(logFile); #ifndef WIN32 -- 1.6.3.2