// // MODULE: APGTSLOG.CPP // // PURPOSE: User Activity Logging Utility // Fully implements class CHTMLLog // // PROJECT: Generic Troubleshooter DLL for Microsoft AnswerPoint // // COMPANY: Saltmine Creative, Inc. (206)-284-7511 support@saltmine.com // // AUTHOR: Roman Mach // // ORIGINAL DATE: 8-2-96 // // NOTES: // 1. Based on Print Troubleshooter DLL // // Version Date By Comments //-------------------------------------------------------------------- // V0.1 - RM Original // #include "stdafx.h" #include "apgtslog.h" #include "event.h" #include "apgts.h" #include "baseexception.h" #include "CharConv.h" #include using namespace std; bool CHTMLLog::s_bUseHTMLLog = false;// Online Troubleshooter, will promptly set this // true in DLLMain. For Local Troubleshooter, // we leave this false. /*static*/ void CHTMLLog::SetUseLog(bool bUseLog) { s_bUseHTMLLog = bUseLog; } // INPUT dirpath: directory where we write log files // If can't allocate memory, sets some m_buffer[i] values to NULL, sets m_dwErr // EV_GTS_ERROR_LOG_FILE_MEM, but still returns normally. Consequently, there's really // no way for the caller to spot a problem, except by calling CHTMLLog::GetStatus after // _every_ call to this function. CHTMLLog::CHTMLLog(const TCHAR *dirpath) : m_bufindex(0), m_dwErr(0), m_strDirPath(dirpath) { ::InitializeCriticalSection( &m_csLogLock ); for (UINT i=0;iGetBuffer(0). // Leave it this way: can't be bad. JM/RAB 3/2/99 fwrite( m_buffer[i]->GetBuffer(0), m_buffer[i]->GetLength(), 1, fp ); m_buffer[i]->ReleaseBuffer(); m_buffer[i]->Empty(); } fclose(fp); } else return EV_GTS_ERROR_LOG_FILE_OPEN; } return (0); } // // Access function to enable the registry monitor to change the logging file directory. // void CHTMLLog::SetLogDirectory( const CString &strNewLogDir ) { Lock(); m_strDirPath= strNewLogDir; Unlock(); return; } // // for testing only // // initially place 0 into dwThreadID // DWORD CHTMLLog::WriteTestLog(LPCTSTR szAPIName, DWORD dwThreadID) { TCHAR filepath[MAX_PATH]; SYSTEMTIME SysTime; DWORD dwRetThreadID = GetCurrentThreadId(); GetLocalTime(&SysTime); _stprintf(filepath,_T("%sAX%02d%02d%02d.log"), m_strDirPath, SysTime.wYear % 100, SysTime.wMonth, SysTime.wDay); Lock(); FILE *fp = _tfopen(filepath, _T("a")); if (fp) { if (!dwThreadID) fprintf(fp, "(Start %s,%d)", szAPIName, dwRetThreadID); else { if (dwThreadID == dwRetThreadID) fprintf(fp, "(%d End)\n", dwThreadID); else fprintf(fp, "(%d End FAIL)\n", dwThreadID); } fclose(fp); } Unlock(); return dwRetThreadID; } void CHTMLLog::Lock() { ::EnterCriticalSection( &m_csLogLock ); } void CHTMLLog::Unlock() { ::LeaveCriticalSection( &m_csLogLock ); }