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++
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;//日志管理对象
|
|
CLogMgr::CLogMgr(void)
|
|
{
|
|
m_bWriteDebugLog = true;
|
|
m_LogListMaxLine = 1000;//日志列表最大的行数,超过时清空
|
|
m_bWriteToLogList = true;//输出到日志列表
|
|
m_pPromptInfo = NULL;//提示信息
|
|
m_bNotWriteSameLog = true;//不要显示连续相同的日志
|
|
m_MaxWorkRecodCnt = 100;//最大加工记录的查询数量,避免数量过大卡死
|
|
}
|
|
CLogMgr::~CLogMgr(void)
|
|
{
|
|
}
|
|
#if 1
|
|
void CLogMgr::OnAppInitialize()
|
|
{
|
|
//创建日志文件的默认路径
|
|
CreatLogFilePath();
|
|
//更新LogFileStream
|
|
UpdateLogFileStream();
|
|
}
|
|
CMFCPropertyGridProperty *CLogMgr::CreatGridProperty()
|
|
{
|
|
CString PropertyName;//属性名称
|
|
CString Description;//描述
|
|
CString Path = _T("LogMgr");;//存储路径
|
|
CString Name;
|
|
CString GroupName;
|
|
CString ModuleName;
|
|
//-------------------------------------------------------------------------------//
|
|
PropertyName = _T("日志");
|
|
GroupName = PropertyName;
|
|
CMFCPropertyGridProperty* pGroup = new CMFCPropertyGridProperty(PropertyName);
|
|
//-------------------------------------------------------------------------------//
|
|
if(gAuthorityMgr->CheckAuthority(_Authority_Engineer))
|
|
{
|
|
//添加属性变量映射
|
|
Name = _T("bWriteDebugLog");//变量名字
|
|
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);//读取保存的属性
|
|
|
|
//添加属性显示
|
|
PropertyName = _T("日志文件");
|
|
Description = _T("是否输出调试日志文件");
|
|
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))
|
|
{
|
|
//添加属性变量映射
|
|
Name = _T("m_bWriteToLogList");//变量名字
|
|
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);//读取保存的属性
|
|
|
|
//添加属性显示
|
|
PropertyName = _T("日志列表");
|
|
Description = _T("是否输出日志列表");
|
|
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))
|
|
{
|
|
//添加属性变量映射
|
|
Name = _T("m_bNotWriteSameLog");//变量名字
|
|
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);//读取保存的属性
|
|
|
|
//添加属性显示
|
|
PropertyName = _T("屏蔽相同日志");
|
|
Description = _T("是否屏蔽相同日志");
|
|
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))
|
|
{
|
|
//添加属性变量映射
|
|
Name = _T("m_LogListMaxLine");//变量名字
|
|
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);//读取保存的属性
|
|
|
|
//添加属性显示
|
|
PropertyName = _T("最大行数");
|
|
Description = _T("日志列表最大的行数,超过时清空日志列表");
|
|
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))
|
|
{
|
|
//添加属性变量映射
|
|
Name = _T("m_MaxWorkRecodCnt");//变量名字
|
|
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);//读取保存的属性
|
|
|
|
//添加属性显示
|
|
PropertyName = _T("查询记录数量");
|
|
Description = _T("最大查询加工记录的数量,避免数量过大卡死");
|
|
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;
|
|
}
|
|
//创建日志文件的默认路径
|
|
void CLogMgr::CreatLogFilePath()
|
|
{
|
|
CString DirPath = GetLogPath();
|
|
CFileMgr FileMgr;
|
|
if(!FileMgr.IsDirectoryExists(DirPath))
|
|
FileMgr.CreatDir(DirPath);
|
|
}
|
|
//更新LogFileStream
|
|
void CLogMgr::UpdateLogFileStream()
|
|
{
|
|
CWorkTime WorkTime;
|
|
CString Date = WorkTime.GetCurDate("_");
|
|
//日期或者指定路径发生变化时
|
|
CString NewLogFilePath = GetLogFilePath();
|
|
if(m_CurDebugLogFilePath != NewLogFilePath)
|
|
{
|
|
CString LogFilePath = NewLogFilePath;
|
|
//关闭之前的
|
|
m_LogFileStream.close();
|
|
//以追加的方式打开
|
|
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();
|
|
//创建当前年的文件夹
|
|
CWorkTime WorkTime;
|
|
LogFilePath += WorkTime.GetCurYear();
|
|
if(!FileMgr.IsDirectoryExists(LogFilePath))
|
|
{
|
|
FileMgr.CreatDir(LogFilePath);
|
|
}
|
|
//创建当前月的文件夹
|
|
LogFilePath += "\\";
|
|
LogFilePath += WorkTime.GetCurMonth();
|
|
if(!FileMgr.IsDirectoryExists(LogFilePath))
|
|
{
|
|
FileMgr.CreatDir(LogFilePath);
|
|
}
|
|
//加上当前的日期
|
|
LogFilePath += "\\";
|
|
CString Date = WorkTime.GetCurDate("_");
|
|
LogFilePath += Date;
|
|
//如果路径不存在则创建目录(每天的目录)
|
|
if(!FileMgr.IsDirectoryExists(LogFilePath))
|
|
{
|
|
FileMgr.CreatDir(LogFilePath);
|
|
}
|
|
CString CurTime = WorkTime.GetCurTime("_");
|
|
LogFilePath += "\\log_";
|
|
LogFilePath += CurTime.Left(2);//每个小时为一个文件
|
|
LogFilePath += ".txt";
|
|
return LogFilePath;
|
|
}
|
|
//打开日志目录
|
|
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
|
|
//写入日志
|
|
void CLogMgr::WriteLog(CLog &Log)
|
|
{
|
|
if(gExitApp)
|
|
return;
|
|
//不要重复输入相同的日志信息
|
|
if(m_bNotWriteSameLog)
|
|
{
|
|
if(m_LastLogStr == Log.str)
|
|
return;
|
|
}
|
|
m_LastLogStr = Log.str;
|
|
CString strTime; //当前时间
|
|
strTime=gWorkTime.GetDateTime("/",":");
|
|
//输出当前线程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 文件
|
|
if(m_bWriteDebugLog)
|
|
{
|
|
m_LogFileStream<<str<<endl;
|
|
}
|
|
}
|
|
void CLogMgr::WriteCmd(CString Cmd,CString val1,CString val2)
|
|
{
|
|
|
|
}
|
|
//输出提示信息
|
|
void CLogMgr::WritePromptInfo(CString Str)
|
|
{
|
|
CString strTime; //当前时间
|
|
strTime=gWorkTime.GetCurTime(":");
|
|
Str = strTime+" "+Str;
|
|
//日志列表
|
|
m_pPromptInfo->AddToList(Str,m_LogListMaxLine);
|
|
}
|
|
CString CLogMgr::GetLastLogStr()
|
|
{
|
|
CString s;
|
|
return s;
|
|
}
|
|
//打开log app
|
|
void CLogMgr::OpenLogListApp()
|
|
{
|
|
}
|
|
void CLogMgr::OpenLogListAppExt()
|
|
{
|
|
|
|
}
|
|
#endif
|
|
#if 1//一些方便的写log 方式
|
|
void CLogMgr::WriteDebugLog(CString Str,LOG_TYPE type)
|
|
{
|
|
//过滤掉太短的日志
|
|
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);
|
|
}
|
|
}
|
|
//两个变量
|
|
void CLogMgr::WriteDebugLog(CString Str,CString ValName1,CString ValName2,double val1,double val2)
|
|
{
|
|
|
|
}
|
|
//一个变量
|
|
void CLogMgr::WriteDebugLog(CString Str,CString ValName,double val)
|
|
{
|
|
|
|
}
|
|
|
|
void CLogMgr::WriteByte(BYTE bit)
|
|
{
|
|
|
|
}
|
|
void CLogMgr::WriteBuf(char *buf,int len)
|
|
{
|
|
|
|
}
|
|
#endif
|