COTSUtilityDllFunExport.cpp 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. #pragma once
  2. #include <stdlib.h>
  3. #include <crtdbg.h>
  4. #include "Logstdafx.h"
  5. #include "COTSUtilityDllFunExport.h"
  6. #include "MyLogger.h"
  7. #define LOGINFO_SWITCH
  8. std::string getFormattedStr( const char *strFormat, va_list arglist)
  9. {
  10. CString str;
  11. str.FormatV(strFormat, arglist);
  12. std::string strFormatted = str;
  13. return strFormatted;
  14. }
  15. MyLogger* myLogFile = NULL;
  16. void InitLogFile(LPCTSTR lpLogName)
  17. {
  18. // is log file created?
  19. if (NULL == myLogFile)
  20. {
  21. myLogFile = new MyLogger();
  22. myLogFile->InitLogFile(lpLogName);
  23. }
  24. }
  25. void LogTrace(LPCTSTR szFile, long lLine, LPCTSTR lpTraceLog, ...)
  26. {
  27. if (NULL == myLogFile)
  28. {
  29. return;
  30. }
  31. std::string strLog;
  32. va_list arglist;
  33. va_start(arglist, lpTraceLog);
  34. strLog = getFormattedStr( lpTraceLog, arglist);
  35. va_end(arglist);
  36. myLogFile->LogTrace( szFile, lLine, (LPCTSTR)strLog.c_str());
  37. }
  38. void LogInfoTrace(LPCTSTR szFile, long lLine, LPCTSTR lpTraceLog, ...)
  39. {
  40. #ifdef LOGINFO_SWITCH
  41. if (NULL == myLogFile)
  42. {
  43. return;
  44. }
  45. std::string strLog;
  46. va_list arglist;
  47. va_start(arglist, lpTraceLog);
  48. strLog = getFormattedStr( lpTraceLog, arglist);
  49. va_end(arglist);
  50. myLogFile->LogInfoTrace(szFile, lLine, (LPCTSTR)strLog.c_str());
  51. #endif
  52. }
  53. void LogErrorTrace(LPCTSTR szFile, long lLine, LPCTSTR lpErrorTrace, ...)
  54. {
  55. if (NULL == myLogFile)
  56. {
  57. return;
  58. }
  59. std::string strLog;
  60. va_list arglist;
  61. va_start(arglist, lpErrorTrace);
  62. strLog = getFormattedStr(lpErrorTrace, arglist);
  63. va_end(arglist);
  64. myLogFile->LogErrorTrace(szFile, lLine, (LPCTSTR)strLog.c_str());
  65. }
  66. void LogBinaryTrace(LPCTSTR szHead, BYTE * pbyData, UINT nLen)
  67. {
  68. if (NULL == myLogFile)
  69. {
  70. // InitLogFile(g_csLogName);
  71. return;
  72. }
  73. myLogFile->LogBinaryTrace(szHead, pbyData, nLen);
  74. }
  75. void WaitingTime(int iMilliseconds)
  76. {
  77. if (NULL == myLogFile)
  78. {
  79. // InitLogFile(g_csLogName);
  80. return;
  81. }
  82. myLogFile->WaitingTime(iMilliseconds);
  83. }
  84. void EndLogFile()
  85. {
  86. if (NULL != myLogFile)
  87. {
  88. delete myLogFile;
  89. myLogFile = NULL;
  90. }
  91. }