| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146 |
- #pragma once
- #include "Logstdafx.h"
- #include "COTSUtilityDllFunExport.h"
- //#include "CLogFile.h"
- #include "MyLogger.h"
- #define LOGINFO_SWITCH
- MyLogger::MyLogger()
- {
- }
- void MyLogger::InitLogFile(LPCTSTR lpLogName)
- {
- // is log file created?
- if (NULL == g_LpLogFile)
- {
- CString csLogPath = GetCompanyLogPathName();
- if (!Exists(csLogPath))
- {
- csLogPath = ".\\Log\\SysMgrApp";
- csLogPath += lpLogName;
- g_LpLogFile = new class CCLogFile(csLogPath);
- }
- else
- {
- csLogPath += lpLogName;
- g_LpLogFile = new class CCLogFile(csLogPath);
- }
- }
- }
- void MyLogger::LogTrace(LPCTSTR szFile, long lLine, LPCTSTR lpTraceLog, ...)
- {
- if (NULL == g_LpLogFile)
- {
- return;
- }
- LPCTSTR szFileName = ::PathFindFileName(szFile);
-
- g_LpLogFile->TraceProgress(szFileName, lLine, lpTraceLog);
- }
- void MyLogger::LogInfoTrace(LPCTSTR szFile, long lLine, LPCTSTR lpTraceLog, ...)
- {
- #ifdef LOGINFO_SWITCH
- if (NULL == g_LpLogFile)
- {
- return;
- }
- LPCTSTR szFileName = ::PathFindFileName(szFile);
-
- g_LpLogFile->TraceProgress(szFileName, lLine, lpTraceLog);
- #endif
- }
- void MyLogger::LogErrorTrace(LPCTSTR szFile, long lLine, LPCTSTR lpErrorTrace, ...)
- {
- if (NULL == g_LpLogFile)
- {
- return;
- }
- LPCTSTR szFileName = ::PathFindFileName(szFile);
-
- g_LpLogFile->TraceError(szFileName, lLine, lpErrorTrace);
- }
- void MyLogger::LogBinaryTrace(LPCTSTR szHead, BYTE * pbyData, UINT nLen)
- {
- if (NULL == g_LpLogFile)
- {
- return;
- }
- g_LpLogFile->LogBinaryData(szHead, pbyData, nLen);
- }
- void MyLogger::WaitingTime(int iMilliseconds)
- {
- if (NULL == m_LpUTools)
- {
- m_LpUTools = new CUtilityTools();
- }
- m_LpUTools->WaitingWithEventLoop(iMilliseconds);
- }
- void MyLogger::EndLogFile()
- {
- if (NULL != g_LpLogFile)
- {
- delete g_LpLogFile;
- g_LpLogFile = NULL;
- }
- if (NULL != m_LpUTools)
- {
- delete m_LpUTools;
- m_LpUTools = NULL;
- }
- }
- MyLogger::~MyLogger()
- {
- EndLogFile();
- }
- CString MyLogger::GetOSCommonDataPathName()
- {
- CString strPathName(".\\");
- return strPathName;
- }
- CString MyLogger::GetCompanyLogPathName()
- { // get common data pathname string
- CString strCommonDataPathName = GetOSCommonDataPathName();
- if (strCommonDataPathName.IsEmpty())
- {
- // failed to get company system data folder string
- LogErrorTrace(__FILE__, __LINE__, _T("GetCompayLogPathName: failed to common data pathname string."));
- return _T("");
- }
- // software package log path
- // e.g. "c:\ProgramData\Log\"
- CString strCompanyLogPathName = strCommonDataPathName + STR_COMPANYNAME + _T("\\") + STR_LOG + _T("\\");
- // return software package log path
- return strCompanyLogPathName;
- }
- BOOL MyLogger::Exists(LPCTSTR a_sPath)
- {
- return ::PathFileExists(a_sPath) == TRUE;
- }
|