From a8a4e9e9751846209019a7354e6721da889f246e Mon Sep 17 00:00:00 2001 From: Juan Carlos Luciani Date: Wed, 2 Jan 2008 17:45:07 +0000 Subject: [PATCH] Added time-stamp and process/thread information to the Windows debug logs. --- .../mechanisms/krb5/windows/platform.h | 45 ++++++++++--------- .../library/mechanisms/pwd/windows/platform.h | 45 ++++++++++--------- .../client/library/windows/platform.h | 11 +++-- 3 files changed, 55 insertions(+), 46 deletions(-) diff --git a/CASA-auth-token/client/library/mechanisms/krb5/windows/platform.h b/CASA-auth-token/client/library/mechanisms/krb5/windows/platform.h index e53dc700..be5a0377 100644 --- a/CASA-auth-token/client/library/mechanisms/krb5/windows/platform.h +++ b/CASA-auth-token/client/library/mechanisms/krb5/windows/platform.h @@ -53,27 +53,30 @@ // } \ //} #define DbgTrace(LEVEL, X, Y) { \ -char formatBuff[128]; \ -char printBuff[256]; \ -FILE *pDebugFile; \ - if (LEVEL == 0 || KrbMechDebugLevel >= LEVEL) \ - { \ - strcpy(formatBuff, "Krb5Mech "); \ - strncat(formatBuff, X, sizeof(formatBuff) - 9); \ - _snprintf(printBuff, sizeof(printBuff), formatBuff, Y); \ - if (pKrbMechDebugLogFilePath) \ - { \ - pDebugFile = fopen(pKrbMechDebugLogFilePath, "a+"); \ - if (pDebugFile) \ - { \ - fwrite(printBuff, strlen(printBuff), 1, pDebugFile); \ - fclose(pDebugFile); \ - } \ - } \ - else \ - OutputDebugString(printBuff); \ - } \ -} +char formatBuff[256]; \ +char printBuff[384]; \ +FILE *pDebugFile; \ + if (LEVEL == 0 || KrbMechDebugLevel >= LEVEL) \ + { \ + SYSTEMTIME sysTime; \ + GetLocalTime(&sysTime); \ + _snprintf(formatBuff, sizeof(formatBuff), "[%X-%X] [%02d:%02d:%02d] CASA_KrbMech ", GetCurrentProcessId(), GetCurrentThreadId(), sysTime.wHour, sysTime.wMinute, sysTime.wSecond); \ + strncat(formatBuff, X, sizeof(formatBuff) - strlen(formatBuff) - 1); \ + _snprintf(printBuff, sizeof(printBuff), formatBuff, Y); \ + if (pKrbMechDebugLogFilePath) \ + { \ + pDebugFile = fopen(pKrbMechDebugLogFilePath, "a+"); \ + if (pDebugFile) \ + { \ + fwrite(printBuff, strlen(printBuff), 1, pDebugFile); \ + fflush(pDebugFile); \ + fclose(pDebugFile); \ + } \ + } \ + else \ + OutputDebugString(printBuff); \ + } \ +} #define INT32_MAX (2147483647) #define UINT32_MAX (4294967295U) diff --git a/CASA-auth-token/client/library/mechanisms/pwd/windows/platform.h b/CASA-auth-token/client/library/mechanisms/pwd/windows/platform.h index e6abcc65..24d42058 100644 --- a/CASA-auth-token/client/library/mechanisms/pwd/windows/platform.h +++ b/CASA-auth-token/client/library/mechanisms/pwd/windows/platform.h @@ -51,27 +51,30 @@ // } \ //} #define DbgTrace(LEVEL, X, Y) { \ -char formatBuff[128]; \ -char printBuff[256]; \ -FILE *pDebugFile; \ - if (LEVEL == 0 || PwdMechDebugLevel >= LEVEL) \ - { \ - strcpy(formatBuff, "CASA_PwdMech "); \ - strncat(formatBuff, X, sizeof(formatBuff) - 8); \ - _snprintf(printBuff, sizeof(printBuff), formatBuff, Y); \ - if (pPwdMechDebugLogFilePath) \ - { \ - pDebugFile = fopen(pPwdMechDebugLogFilePath, "a+"); \ - if (pDebugFile) \ - { \ - fwrite(printBuff, strlen(printBuff), 1, pDebugFile); \ - fclose(pDebugFile); \ - } \ - } \ - else \ - OutputDebugString(printBuff); \ - } \ -} +char formatBuff[256]; \ +char printBuff[384]; \ +FILE *pDebugFile; \ + if (LEVEL == 0 || PwdMechDebugLevel >= LEVEL) \ + { \ + SYSTEMTIME sysTime; \ + GetLocalTime(&sysTime); \ + _snprintf(formatBuff, sizeof(formatBuff), "[%X-%X] [%02d:%02d:%02d] CASA_PwdMech ", GetCurrentProcessId(), GetCurrentThreadId(), sysTime.wHour, sysTime.wMinute, sysTime.wSecond); \ + strncat(formatBuff, X, sizeof(formatBuff) - strlen(formatBuff) - 1); \ + _snprintf(printBuff, sizeof(printBuff), formatBuff, Y); \ + if (pPwdMechDebugLogFilePath) \ + { \ + pDebugFile = fopen(pPwdMechDebugLogFilePath, "a+"); \ + if (pDebugFile) \ + { \ + fwrite(printBuff, strlen(printBuff), 1, pDebugFile); \ + fflush(pDebugFile); \ + fclose(pDebugFile); \ + } \ + } \ + else \ + OutputDebugString(printBuff); \ + } \ +} #define INT32_MAX (2147483647) #define UINT32_MAX (4294967295U) diff --git a/CASA-auth-token/client/library/windows/platform.h b/CASA-auth-token/client/library/windows/platform.h index 5dc8b8ff..dc94b0bd 100644 --- a/CASA-auth-token/client/library/windows/platform.h +++ b/CASA-auth-token/client/library/windows/platform.h @@ -53,13 +53,15 @@ // } \ //} #define DbgTrace(LEVEL, X, Y) { \ -char formatBuff[128]; \ -char printBuff[256]; \ +char formatBuff[256]; \ +char printBuff[384]; \ FILE *pDebugFile; \ if (LEVEL == 0 || DebugLevel >= LEVEL) \ { \ - strcpy(formatBuff, "CASA_AuthToken "); \ - strncat(formatBuff, X, sizeof(formatBuff) - 10); \ + SYSTEMTIME sysTime; \ + GetLocalTime(&sysTime); \ + _snprintf(formatBuff, sizeof(formatBuff), "[%X-%X] [%02d:%02d:%02d] CASA_AuthToken ", GetCurrentProcessId(), GetCurrentThreadId(), sysTime.wHour, sysTime.wMinute, sysTime.wSecond); \ + strncat(formatBuff, X, sizeof(formatBuff) - strlen(formatBuff) - 1); \ _snprintf(printBuff, sizeof(printBuff), formatBuff, Y); \ if (g_pDebugLogFilePath) \ { \ @@ -67,6 +69,7 @@ FILE *pDebugFile; \ if (pDebugFile) \ { \ fwrite(printBuff, strlen(printBuff), 1, pDebugFile); \ + fflush(pDebugFile); \ fclose(pDebugFile); \ } \ } \