CLogFile.h 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. #pragma once
  2. #include <afxmt.h>
  3. enum TRACER_TYPE
  4. {
  5. TRACER_OPE_PROGRESS = 0 /**< To indicate progress of operation. */
  6. , TRACER_OPE_ERROR = 1 /**< To indicate Error is happened. */
  7. , TRACER_OPE_EXCEPTION = 2 /**< To indicate exceptions. */
  8. , TRACER_OPE_MESSAGE = 3 /**< To indicate message display. */
  9. };
  10. #define TRACER_OPE_PROGRESS_STR _T("_TRACE_: ")/**< To indicate progress of operation. */
  11. #define TRACER_OPE_ERROR_STR _T("_ERROR_: ")/**< To indicate Error is happened. */
  12. #define TRACER_OPE_EXCEPTION_STR _T("_EXCEPT_: ")/**< To indicate exceptions. */
  13. #define TRACER_OPE_MESSAGE_STR _T("_MSG_: ")/**< To indicate message display */
  14. class CCLogFile
  15. {
  16. public:
  17. CCLogFile(LPCTSTR szFileName, bool bLogNeedManage = true);
  18. ~CCLogFile();
  19. public:
  20. void Print(LPCTSTR szData, ...);
  21. void Print(TRACER_TYPE nType, LPCTSTR szData, ...);
  22. void TraceProgress(LPCTSTR szFile, long lLine, LPCTSTR szData, ...);
  23. void TraceError(LPCTSTR szFile, long lLine, LPCTSTR szData, ...);
  24. void TraceException(LPCTSTR szFile, long lLine, LPCTSTR szData, ...);
  25. void TraceMessage(LPCTSTR szFile, long lLine, LPCTSTR szData, ...);
  26. void LogBinaryData(LPCTSTR szHead, BYTE* pbyData, UINT nLen);
  27. CString WChar2Ansi(LPCTSTR pwszSrc);
  28. CString StringToWString(const CString& s);
  29. private: // Methods.
  30. void LogFile(LPCTSTR szData);
  31. void PrintV(LPCTSTR pszFormat, va_list pArgList);
  32. void PrintV(TRACER_TYPE nType, LPCTSTR pszFormat, va_list pArgList);
  33. bool CheckFilePath(const CString& strPath);
  34. HANDLE CreateLogFile(const CString& str);
  35. private: // Data.
  36. CString m_szFile;
  37. ///@cond CHS
  38. ///临界区变量
  39. ///@endcond
  40. ///@cond ENG
  41. ///Critical Section for text log
  42. ///@endcond
  43. CCriticalSection m_csLog;
  44. ///@cond CHS
  45. ///记录二进制数据临界区变量
  46. ///@endcond
  47. ///@cond ENG
  48. ///Critical Section for binary log
  49. ///@endcond
  50. CCriticalSection m_csBinLog;
  51. ///@cond CHS
  52. ///日志文件名是否已经提交到LogManager
  53. ///@endcond
  54. ///@cond ENG
  55. ///Log filename commit to LogManager flag
  56. ///@endcond
  57. bool m_bFileNameCommited;
  58. };
  59. class CUtilityTools
  60. {
  61. public:
  62. CUtilityTools(){}
  63. ~CUtilityTools()
  64. {
  65. }
  66. public:
  67. void WaitingWithEventLoop(int iWaitTime);
  68. };