#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; }