You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

349 lines
11 KiB
C++

#include "StdAfx.h"
#include "LogMgr.h"
#include "MainFrm.h"
#include "FileMgr.h"
#include "Propertie.h"
#include "PropertieMgr.h"
#include "BitOperation.h"
#include "AuthorityMgr.h"
#include "WorkTime.h"
#include "CStringFuc.h"
#include "CriticalSection.h"
#include "GlobalFunction.h"
#include "MyDlgView.h"
#include "DlgChildEventLog.h"
#define LOG_FILE_PATH _T("\\LogFile_DataMgr\\")
#define WNDS_NAME_LaipuLog "Laipu Log"
#define FILE_Name_LaipuLog ("\\LogMgrDlg.exe")
CLogMgr* gLogMgr = NULL;//<2F><>־<EFBFBD><D6BE><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
CLogMgr::CLogMgr(void)
{
m_bWriteDebugLog = true;
m_LogListMaxLine = 1000;//<2F><>־<EFBFBD>б<EFBFBD><D0B1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>,<2C><><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD>
m_bWriteToLogList = true;//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>־<EFBFBD>б<EFBFBD>
m_pPromptInfo = NULL;//<2F><>ʾ<EFBFBD><CABE>Ϣ
m_bNotWriteSameLog = true;//<2F><>Ҫ<EFBFBD><D2AA>ʾ<EFBFBD><CABE><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͬ<EFBFBD><CDAC><EFBFBD><EFBFBD>־
m_MaxWorkRecodCnt = 100;//<2F><><EFBFBD><EFBFBD><EFBFBD>ӹ<EFBFBD><D3B9><EFBFBD>¼<EFBFBD>IJ<EFBFBD>ѯ<EFBFBD><D1AF><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
}
CLogMgr::~CLogMgr(void)
{
}
#if 1
void CLogMgr::OnAppInitialize()
{
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>־<EFBFBD>ļ<EFBFBD><C4BC><EFBFBD>Ĭ<EFBFBD><C4AC>·<EFBFBD><C2B7>
CreatLogFilePath();
//<2F><><EFBFBD><EFBFBD>LogFileStream
UpdateLogFileStream();
}
CMFCPropertyGridProperty *CLogMgr::CreatGridProperty()
{
CString PropertyName;//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
CString Description;//<2F><><EFBFBD><EFBFBD>
CString Path = _T("LogMgr");;//<2F>洢·<E6B4A2><C2B7>
CString Name;
CString GroupName;
CString ModuleName;
//-------------------------------------------------------------------------------//
PropertyName = _T("<EFBFBD><EFBFBD>־");
GroupName = PropertyName;
CMFCPropertyGridProperty* pGroup = new CMFCPropertyGridProperty(PropertyName);
//-------------------------------------------------------------------------------//
if(gAuthorityMgr->CheckAuthority(_Authority_Engineer))
{
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ա<EFBFBD><D4B1><EFBFBD>ӳ<EFBFBD><D3B3>
Name = _T("bWriteDebugLog");//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
CPropertie *pPropertie = new CPropertie;
pPropertie->SetpVal((void*)&m_bWriteDebugLog);
pPropertie->SetType(_PROP_TYPE_BOOL);
pPropertie->SetpModule(this);
pPropertie->SetPath(Path);
pPropertie->SetName(Name);
pPropertie->WriteRead(true);//<2F><>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʾ
PropertyName = _T("<EFBFBD><EFBFBD>־<EFBFBD>ļ<EFBFBD>");
Description = _T("<EFBFBD>Ƿ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>־<EFBFBD>ļ<EFBFBD>");
pPropertie->SetGroupName(GroupName);
pPropertie->SetShowName(PropertyName);
CMFCPropertyGridProperty* p1 = new CMFCPropertyGridProperty(PropertyName, (_variant_t)m_bWriteDebugLog, Description);
pGroup->AddSubItem(p1);
gDevicePropertieMgr.Insert(p1, pPropertie);
}
if(gAuthorityMgr->CheckAuthority(_Authority_Engineer))
{
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ա<EFBFBD><D4B1><EFBFBD>ӳ<EFBFBD><D3B3>
Name = _T("m_bWriteToLogList");//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
CPropertie *pPropertie = new CPropertie;
pPropertie->SetpVal((void*)&m_bWriteToLogList);
pPropertie->SetType(_PROP_TYPE_BOOL);
pPropertie->SetpModule(this);
pPropertie->SetPath(Path);
pPropertie->SetName(Name);
pPropertie->WriteRead(true);//<2F><>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʾ
PropertyName = _T("<EFBFBD><EFBFBD>־<EFBFBD>б<EFBFBD>");
Description = _T("<EFBFBD>Ƿ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>־<EFBFBD>б<EFBFBD>");
pPropertie->SetGroupName(GroupName);
pPropertie->SetShowName(PropertyName);
CMFCPropertyGridProperty* p1 = new CMFCPropertyGridProperty(PropertyName, (_variant_t)m_bWriteToLogList, Description);
pGroup->AddSubItem(p1);
gDevicePropertieMgr.Insert(p1, pPropertie);
}
if(gAuthorityMgr->CheckAuthority(_Authority_Engineer))
{
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ա<EFBFBD><D4B1><EFBFBD>ӳ<EFBFBD><D3B3>
Name = _T("m_bNotWriteSameLog");//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
CPropertie *pPropertie = new CPropertie;
pPropertie->SetpVal((void*)&m_bNotWriteSameLog);
pPropertie->SetType(_PROP_TYPE_BOOL);
pPropertie->SetpModule(this);
pPropertie->SetPath(Path);
pPropertie->SetName(Name);
pPropertie->WriteRead(true);//<2F><>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʾ
PropertyName = _T("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͬ<EFBFBD><EFBFBD>־");
Description = _T("<EFBFBD>Ƿ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͬ<EFBFBD><EFBFBD>־");
pPropertie->SetGroupName(GroupName);
pPropertie->SetShowName(PropertyName);
CMFCPropertyGridProperty* p1 = new CMFCPropertyGridProperty(PropertyName, (_variant_t)m_bNotWriteSameLog, Description);
pGroup->AddSubItem(p1);
gDevicePropertieMgr.Insert(p1, pPropertie);
}
if(gAuthorityMgr->CheckAuthority(_Authority_Factory))
{
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ա<EFBFBD><D4B1><EFBFBD>ӳ<EFBFBD><D3B3>
Name = _T("m_LogListMaxLine");//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
CPropertie *pPropertie = new CPropertie;
pPropertie->SetpVal((void*)&m_LogListMaxLine);
pPropertie->SetType(_PROP_TYPE_INT);
pPropertie->SetpModule(this);
pPropertie->SetPath(Path);
pPropertie->SetName(Name);
pPropertie->WriteRead(true);//<2F><>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʾ
PropertyName = _T("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>");
Description = _T("<EFBFBD><EFBFBD>־<EFBFBD>б<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>,<2C><><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD><EFBFBD><EFBFBD>־<EFBFBD>б<EFBFBD>");
pPropertie->SetGroupName(GroupName);
pPropertie->SetShowName(PropertyName);
CMFCPropertyGridProperty* p1 = new CMFCPropertyGridProperty(PropertyName, (_variant_t)m_LogListMaxLine, Description);
pGroup->AddSubItem(p1);
gDevicePropertieMgr.Insert(p1, pPropertie);
}
if(gAuthorityMgr->CheckAuthority(_Authority_Factory))
{
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ա<EFBFBD><D4B1><EFBFBD>ӳ<EFBFBD><D3B3>
Name = _T("m_MaxWorkRecodCnt");//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
CPropertie *pPropertie = new CPropertie;
pPropertie->SetpVal((void*)&m_MaxWorkRecodCnt);
pPropertie->SetType(_PROP_TYPE_INT);
pPropertie->SetpModule(this);
pPropertie->SetPath(Path);
pPropertie->SetName(Name);
pPropertie->WriteRead(true);//<2F><>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʾ
PropertyName = _T("<EFBFBD><EFBFBD>ѯ<EFBFBD><EFBFBD>¼<EFBFBD><EFBFBD><EFBFBD><EFBFBD>");
Description = _T("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ѯ<EFBFBD>ӹ<EFBFBD><EFBFBD><EFBFBD>¼<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>");
pPropertie->SetGroupName(GroupName);
pPropertie->SetShowName(PropertyName);
CMFCPropertyGridProperty* p1 = new CMFCPropertyGridProperty(PropertyName, (_variant_t)m_MaxWorkRecodCnt, Description);
pGroup->AddSubItem(p1);
gDevicePropertieMgr.Insert(p1, pPropertie);
}
//-------------------------------------------------------------------------------//
return pGroup;
}
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>־<EFBFBD>ļ<EFBFBD><C4BC><EFBFBD>Ĭ<EFBFBD><C4AC>·<EFBFBD><C2B7>
void CLogMgr::CreatLogFilePath()
{
CString DirPath = GetLogPath();
CFileMgr FileMgr;
if(!FileMgr.IsDirectoryExists(DirPath))
FileMgr.CreatDir(DirPath);
}
//<2F><><EFBFBD><EFBFBD>LogFileStream
void CLogMgr::UpdateLogFileStream()
{
CWorkTime WorkTime;
CString Date = WorkTime.GetCurDate("_");
//<2F><><EFBFBD>ڻ<EFBFBD><DABB><EFBFBD>ָ<EFBFBD><D6B8>·<EFBFBD><C2B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>仯ʱ
CString NewLogFilePath = GetLogFilePath();
if(m_CurDebugLogFilePath != NewLogFilePath)
{
CString LogFilePath = NewLogFilePath;
//<2F>ر<EFBFBD>֮ǰ<D6AE><C7B0>
m_LogFileStream.close();
//<2F><>׷<EFBFBD>ӵķ<D3B5>ʽ<EFBFBD><CABD><EFBFBD><EFBFBD>
m_LogFileStream.open(LogFilePath, ios::app);
m_CurDebugLogFilePath = NewLogFilePath;
WriteDebugLog("Func---->UpdateLogFileStream");
WriteDebugLog(LogFilePath);
}
}
CString CLogMgr::GetLogPath()
{
CString DirPath = gProgramLaserTuiHuo->GetLaipuLaserDataDir(LOG_FILE_PATH);
return DirPath;
}
CString CLogMgr::GetLogFilePath()
{
CFileMgr FileMgr;
CString LogFilePath = GetLogPath();
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ǰ<EFBFBD><C7B0><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD><C4BC><EFBFBD>
CWorkTime WorkTime;
LogFilePath += WorkTime.GetCurYear();
if(!FileMgr.IsDirectoryExists(LogFilePath))
{
FileMgr.CreatDir(LogFilePath);
}
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ǰ<EFBFBD>µ<EFBFBD><C2B5>ļ<EFBFBD><C4BC><EFBFBD>
LogFilePath += "\\";
LogFilePath += WorkTime.GetCurMonth();
if(!FileMgr.IsDirectoryExists(LogFilePath))
{
FileMgr.CreatDir(LogFilePath);
}
//<2F><><EFBFBD>ϵ<EFBFBD>ǰ<EFBFBD><C7B0><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
LogFilePath += "\\";
CString Date = WorkTime.GetCurDate("_");
LogFilePath += Date;
//<2F><><EFBFBD><EFBFBD>·<EFBFBD><C2B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>򴴽<EFBFBD>Ŀ¼(ÿ<><C3BF><EFBFBD><EFBFBD>Ŀ¼)
if(!FileMgr.IsDirectoryExists(LogFilePath))
{
FileMgr.CreatDir(LogFilePath);
}
CString CurTime = WorkTime.GetCurTime("_");
LogFilePath += "\\log_";
LogFilePath += CurTime.Left(2);//ÿ<><C3BF>СʱΪһ<CEAA><D2BB><EFBFBD>ļ<EFBFBD>
LogFilePath += ".txt";
return LogFilePath;
}
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>־Ŀ¼
void CLogMgr::OpenLogFileDir()
{
gLogMgr->WriteDebugLog("Func---->OpenLogFileDir");
if(gAuthorityMgr->CheckAuthority(_Authority_Engineer,true)==false)
return;
CString DirPath = GetLogPath();
CFileMgr FileMgr;
FileMgr.OpenDir(DirPath);
}
#endif
#if 1
//д<><D0B4><EFBFBD><EFBFBD>־
void CLogMgr::WriteLog(CLog &Log)
{
if(gExitApp)
return;
//<2F><>Ҫ<EFBFBD>ظ<EFBFBD><D8B8><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͬ<EFBFBD><CDAC><EFBFBD><EFBFBD>־<EFBFBD><D6BE>Ϣ
if(m_bNotWriteSameLog)
{
if(m_LastLogStr == Log.str)
return;
}
m_LastLogStr = Log.str;
CString strTime; //<2F><>ǰʱ<C7B0><CAB1>
strTime=gWorkTime.GetDateTime("/",":");
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ǰ<EFBFBD>߳<EFBFBD>ID
CString ThreadId;
ThreadId.Format("<%ld>",GetCurrentThreadId());
CString str = strTime + ThreadId;
str = str + " "+Log.str;
CDlgChildEventLog *pDlgChild = dynamic_cast<CDlgChildEventLog*>(gChildEventLog);
pDlgChild->InsertLogToList(str,_LogListType_LaipuDrawing);
//д<>뵽log <20>ļ<EFBFBD>
if(m_bWriteDebugLog)
{
m_LogFileStream<<str<<endl;
}
}
void CLogMgr::WriteCmd(CString Cmd,CString val1,CString val2)
{
}
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʾ<EFBFBD><CABE>Ϣ
void CLogMgr::WritePromptInfo(CString Str)
{
CString strTime; //<2F><>ǰʱ<C7B0><CAB1>
strTime=gWorkTime.GetCurTime(":");
Str = strTime+" "+Str;
//<2F><>־<EFBFBD>б<EFBFBD>
m_pPromptInfo->AddToList(Str,m_LogListMaxLine);
}
CString CLogMgr::GetLastLogStr()
{
CString s;
return s;
}
//<2F><><EFBFBD><EFBFBD>log app
void CLogMgr::OpenLogListApp()
{
}
void CLogMgr::OpenLogListAppExt()
{
}
#endif
#if 1//һЩ<D2BB><D0A9><EFBFBD><EFBFBD><EFBFBD><EFBFBD>дlog <20><>ʽ
void CLogMgr::WriteDebugLog(CString Str,LOG_TYPE type)
{
//<2F><><EFBFBD>˵<EFBFBD>̫<EFBFBD>̵<EFBFBD><CCB5><EFBFBD>־
if(Str.GetLength()<3)
return;
if(m_bWriteDebugLog)
{
CLog log;
log.AddDebugLog();
switch(type)
{
case _LOG_ERROR:
Str = "[Error]"+Str;
break;
case _LOG_FUNC:
Str = "[Function]"+Str;
break;
default:
break;
}
CString str1 = Str;
log.str = str1;
WriteLog(log);
}
}
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
void CLogMgr::WriteDebugLog(CString Str,CString ValName1,CString ValName2,double val1,double val2)
{
}
//һ<><D2BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
void CLogMgr::WriteDebugLog(CString Str,CString ValName,double val)
{
}
void CLogMgr::WriteByte(BYTE bit)
{
}
void CLogMgr::WriteBuf(char *buf,int len)
{
}
#endif