#pragma once #include #include #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; } }