/* * Copyright (c) 1998-2000 by KVA Software * All rights reserved. * * File: dbg.h * Contents: CDebugPrintf class definition * Author: Vladimir Kirienko * * http://www.uran.net/kva * kirienko@geocities.com */ #ifndef ______DBG_H______ #define ______DBG_H______ // #define USE_STL #undef USE_STL // #define USE_MFC #undef USE_MFC #undef USE_DEBUG_PRINTF #if defined(_DEBUG) || defined(DEBUG_PRINTF) #define USE_DEBUG_PRINTF #endif #include "Utility.h" #ifdef USE_DEBUG_PRINTF #ifdef USE_STL #include using namespace std; #endif /* * Macro definitions * */ #define IFDEBUG(doit) doit #define PRINTF debug.printf #define SHOW_CONSOLE debug.ShowConsole(); #define HIDE_CONSOLE debug.HideConsole(); #define SHOW_LASTERROR debug.ShowLastError(); #define CLOSE_LOG debug.CloseLog(); /*----------------------------------------------------------------------- * Class : CDebugPrintf * Prototype : class CDebugPrintf * Description : * Parent class : * History : */ class CDebugPrintf { public: bool LogStarted(); void StopLog(); void StartLog(char *cFilename = NULL); CDebugPrintf(int nDebugType = 0); virtual ~CDebugPrintf(); void printf(const char *str); #ifdef USE_STL void printf(string& str) { printf(str.c_str()); } void printf(string* str) { printf(str->c_str()); } #endif #ifdef USE_MFC void printf(CString& str) { printf(str.GetBuffer(1024)); } void printf(CString* str) { printf(str->GetBuffer(1024)); } #endif void CloseLog(); void ShowConsole(); void HideConsole(); void ShowLastError(); private: HANDLE m_hFile; // log-file handle HANDLE m_hDebugMutex; // allow to check that log-file is open by other process CRITICAL_SECTION m_hLock; // lock for thread-safe access bool m_bUseConsole; // use or not log-console with log-file int m_nDebugType; // to indicate debug type. 0 for debug log (TRACE), 1 for debug timing char m_cFileName[256]; char m_cMutexName[256]; CHighResPerformanceCounter m_HighResCounter; long m_nDebugLogCounter; long m_nNoOfDebugLogSetting; long m_nDebugLogFileSizSetting; long m_nNoOfEventLogSetting; long m_nEventLogFileSizSetting; // Gary 1.16.04, allow to log by day bool m_bLogByDay; CString m_csLogByDayPath; long m_lLastLogByDateTime; CIniFile m_eventLogIni; }; // extern CDebugPrintf debug; // extern CDebugPrintf debugTiming; #else #define IFDEBUG(doit) #define SLASH / #define COMMENT ; SLASH / #define PRINTF COMMENT #define SHOW_CONSOLE COMMENT #define HIDE_CONSOLE COMMENT #define SHOW_LASTERROR COMMENT #define CLOSE_LOG COMMENT #endif #endif