Log.h 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. // Log.h: interface for the CLog class.
  2. //
  3. //////////////////////////////////////////////////////////////////////
  4. //ÈÕÖ¾Éú³ÉÀà
  5. #if !defined(AFX_LOG_H__AAF3D405_307B_4E82_897B_1B2DA3810F1B__INCLUDED_)
  6. #define AFX_LOG_H__AAF3D405_307B_4E82_897B_1B2DA3810F1B__INCLUDED_
  7. #if _MSC_VER > 1000
  8. #pragma once
  9. #endif // _MSC_VER > 1000
  10. #include "BaseUtility.h"
  11. #include "Instance.h"
  12. class CLog : public Instance<CLog>
  13. {
  14. enum enmLogLevel{
  15. LogLvlFatal = 0,
  16. LogLvlFailed,
  17. LogLvlError,
  18. LogLvlWarnning,
  19. LogLvlInfo,
  20. LogLvlTrace,
  21. LogLvlDebug,
  22. LogLvlAll
  23. };
  24. friend class Instance<CLog>;
  25. private:
  26. CLog();
  27. public:
  28. ~CLog();
  29. public:
  30. void SetMinLevel(UINT nLevel){m_nMinLevel=nLevel;};
  31. void Put(const wchar_t* pszMsg, UINT nLevel = LogLvlFatal);
  32. void Put(char* pszMsg, UINT nLevel = LogLvlFatal);
  33. void PutMsg(const char *szFmt, ...);
  34. void PutMsg(const wchar_t * szFmt, ...);
  35. BOOL Init(const char* pszFileName,UINT nMinLevel,UINT nMaxSizeMB=10);
  36. protected:
  37. UINT m_nMinLevel;
  38. UINT m_nMaxLogSize;
  39. #ifdef _LOGCONSOLE
  40. CThreadPrintLog _loger;
  41. #else
  42. typedef struct __tagLogIndex{
  43. DWORD dwPos;
  44. DWORD dwLen;
  45. BYTE nLevel;
  46. __tagLogIndex():dwPos(0L),dwLen(0L),nLevel(LogLvlAll)
  47. {
  48. };
  49. }LOGINDEX;
  50. HANDLE m_hFile;
  51. LOGINDEX m_idx;
  52. char m_chFileName[260];
  53. CRITICAL_SECTION m_cs;
  54. #endif // _DEBUG
  55. };
  56. #endif // !defined(AFX_LOG_H__AAF3D405_307B_4E82_897B_1B2DA3810F1B__INCLUDED_)