// Log.h: interface for the CLog class. // ////////////////////////////////////////////////////////////////////// #pragma once #include #include using namespace std; enum enmLogLevel{ LogLvlFatal=0, LogLvlFailed, LogLvlError, LogLvlWarn, LogLvlInfo, LogLvlTrace, LogLvlDebug, LogLvlAll }; class CLog { public: CLog(); ~CLog(); public: void SetMinLevel(UINT nLevel){m_nMinLevel=nLevel;}; void Put(wstring Msg, UINT nLevel = LogLvlFatal); void Put(string Msg, UINT nLevel = LogLvlFatal); void PutMsg(UINT nLevel,const char *szFmt, ...); BOOL Init(const char* pszFileName,UINT nMinLevel,int nMaxSize=1*1024*1024); protected: UINT m_nMinLevel; UINT m_nMaxLogSize; static string logDescripe[]; typedef struct __tagLogIndex{ DWORD dwPos; DWORD dwLen; BYTE nLevel; __tagLogIndex():dwPos(0L),dwLen(0L),nLevel(LogLvlAll) { }; }LOGINDEX; HANDLE m_hFile; LOGINDEX m_idx; string m_FileName; CRITICAL_SECTION m_cs; char* m_pBuf; int m_bufSize; }; class CFunc_trace { public: string funname; CLog* plog; UINT loglevel; string time; CFunc_trace(string name, CLog* log, UINT level) { funname = name; plog = log; loglevel = level; SYSTEMTIME st; GetLocalTime(&st); char chBuf[24] = { 0 }; sprintf(chBuf, "%02d:%02d_%02d ",st.wMinute, st.wSecond,st.wMilliseconds); time = chBuf; if (plog) { plog->PutMsg(loglevel, "+++ %s %s +++", funname.c_str(),time.c_str()); } } ~CFunc_trace() { if (plog) { plog->PutMsg(loglevel, "--- %s %s ---", funname.c_str(), time.c_str()); } } };