123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157 |
- #pragma once
- #include <stdlib.h>
- #include <crtdbg.h>
- #include "Logstdafx.h"
- #include "COTSUtilityDllFunExport.h"
- #include "CLogFile.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;
- }
- CString GetLogPathName()
- { // get common data pathname string
- CString strCommonDataPathName = ".\\";
-
- CString strLogPathName = strCommonDataPathName + "Log" + _T("\\");
- // return software package log path
- return strLogPathName;
- }
- BOOL Exists(LPCTSTR a_sPath)
- {
- return ::PathFileExists(a_sPath) == TRUE;
- }
- const CString g_csLogName = "OTSLog";
- const CString STR_LOG = _T("Log");
- CCLogFile* g_LpLogFile = NULL;
- void InitLogFile(LPCTSTR lpLogName)
- {
- // is log file created?
- if (NULL == g_LpLogFile)
- {
- CString csLogPath = GetLogPathName();
- if (!Exists(csLogPath))
- {
- csLogPath = ".\\Log\\SysMgrApp";
- csLogPath += lpLogName;
- g_LpLogFile = new class CCLogFile(csLogPath);
- }
- else
- {
- csLogPath += lpLogName;
- g_LpLogFile = new class CCLogFile(csLogPath);
- }
- }
-
-
-
- }
- void LogTrace(LPCTSTR szFile, long lLine, LPCTSTR lpTraceLog, ...)
- {
- if (NULL == g_LpLogFile)
- {
- InitLogFile(g_csLogName);
- }
- std::string strLog;
- va_list arglist;
- va_start(arglist, lpTraceLog);
- strLog = getFormattedStr( lpTraceLog, arglist);
- va_end(arglist);
- LPCTSTR szFileName = ::PathFindFileName(szFile);
- g_LpLogFile->TraceProgress(szFileName, lLine, (LPCSTR)strLog.c_str());
- }
- void LogInfoTrace(LPCTSTR szFile, long lLine, LPCTSTR lpTraceLog, ...)
- {
- #ifdef LOGINFO_SWITCH
- if (NULL == g_LpLogFile)
- {
- InitLogFile(g_csLogName);
- }
- std::string strLog;
- va_list arglist;
- va_start(arglist, lpTraceLog);
- strLog = getFormattedStr( lpTraceLog, arglist);
- va_end(arglist);
- LPCTSTR szFileName = ::PathFindFileName(szFile);
- g_LpLogFile->TraceProgress(szFileName, lLine, (LPCSTR)strLog.c_str());
- #endif
- }
- void LogErrorTrace(LPCTSTR szFile, long lLine, LPCTSTR lpErrorTrace, ...)
- {
- if (NULL == g_LpLogFile)
- {
- InitLogFile(g_csLogName);
- }
- std::string strLog;
- va_list arglist;
- va_start(arglist, lpErrorTrace);
- strLog = getFormattedStr(lpErrorTrace, arglist);
- va_end(arglist);
- LPCTSTR szFileName = ::PathFindFileName(szFile);
- g_LpLogFile->TraceError(szFileName, lLine, (LPCSTR)strLog.c_str());
- }
- void LogBinaryTrace(LPCTSTR szHead, BYTE * pbyData, UINT nLen)
- {
- if (NULL == g_LpLogFile)
- {
- InitLogFile(g_csLogName);
-
- }
- g_LpLogFile->LogBinaryData(szHead, pbyData, nLen);
- }
- void WaitingTime(int iMilliseconds)
- {
-
- auto m_LpUTools = new CUtilityTools();
-
- m_LpUTools->WaitingWithEventLoop(iMilliseconds);
- delete m_LpUTools;
- }
- void EndLogFile()
- {
- if (NULL != g_LpLogFile)
- {
- delete g_LpLogFile;
- g_LpLogFile = NULL;
- }
-
- }
|