| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121 |
- #pragma once
- #include <stdlib.h>
- #include <crtdbg.h>
- #include "Logstdafx.h"
- #include "COTSUtilityDllFunExport.h"
- #include "MyLogger.h"
- #define LOGINFO_SWITCH
- std::string getFormattedStr( const char *strFormat, va_list arglist)
- {
- CString str;
- str.FormatV(strFormat, arglist);
- std::string strFormatted = str;
- return strFormatted;
- }
- MyLogger* myLogFile = NULL;
- void InitLogFile(LPCTSTR lpLogName)
- {
- // is log file created?
- if (NULL == myLogFile)
- {
- myLogFile = new MyLogger();
- myLogFile->InitLogFile(lpLogName);
-
- }
- }
- void LogTrace(LPCTSTR szFile, long lLine, LPCTSTR lpTraceLog, ...)
- {
- if (NULL == myLogFile)
- {
- return;
- }
- std::string strLog;
- va_list arglist;
- va_start(arglist, lpTraceLog);
- strLog = getFormattedStr( lpTraceLog, arglist);
- va_end(arglist);
- myLogFile->LogTrace( szFile, lLine, (LPCTSTR)strLog.c_str());
- }
- void LogInfoTrace(LPCTSTR szFile, long lLine, LPCTSTR lpTraceLog, ...)
- {
- #ifdef LOGINFO_SWITCH
- if (NULL == myLogFile)
- {
- return;
- }
- std::string strLog;
- va_list arglist;
- va_start(arglist, lpTraceLog);
- strLog = getFormattedStr( lpTraceLog, arglist);
- va_end(arglist);
- myLogFile->LogInfoTrace(szFile, lLine, (LPCTSTR)strLog.c_str());
- #endif
- }
- void LogErrorTrace(LPCTSTR szFile, long lLine, LPCTSTR lpErrorTrace, ...)
- {
- if (NULL == myLogFile)
- {
- return;
- }
- std::string strLog;
- va_list arglist;
- va_start(arglist, lpErrorTrace);
- strLog = getFormattedStr(lpErrorTrace, arglist);
- va_end(arglist);
- myLogFile->LogErrorTrace(szFile, lLine, (LPCTSTR)strLog.c_str());
- }
- void LogBinaryTrace(LPCTSTR szHead, BYTE * pbyData, UINT nLen)
- {
- if (NULL == myLogFile)
- {
- // InitLogFile(g_csLogName);
- return;
- }
- myLogFile->LogBinaryTrace(szHead, pbyData, nLen);
- }
- void WaitingTime(int iMilliseconds)
- {
- if (NULL == myLogFile)
- {
- // InitLogFile(g_csLogName);
- return;
- }
-
- myLogFile->WaitingTime(iMilliseconds);
- }
- void EndLogFile()
- {
- if (NULL != myLogFile)
- {
- delete myLogFile;
- myLogFile = NULL;
- }
-
- }
|