123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140 |
- //-----------------------------调用示例--------------------------------Begin
- ////引用库
- //#include "..\DCAccessWrapperCPlus\DCAccessWrapperCPlus.h"
- //using namespace DCAccess;
- //
- ////用户可以重新初始化覆盖默认设置
- //gLogManage.InitInstance(
- // CDCAccessPro_Ip.GetBuffer(),
- // CDCAccessPro_Port.GetBuffer(),
- // CDCAccessPro_TargetId.GetBuffer());
- //
- //CDCAccessPro_Ip.ReleaseBuffer();
- //CDCAccessPro_Port.ReleaseBuffer();
- //CDCAccessPro_TargetId.ReleaseBuffer();
- //
- //SLogRecordPo tmplog;
- //tmplog.Modules = "GEN";
- //tmplog.MsgId = "1";
- //tmplog.Source = "Generator";
- //tmplog.HostName = "Hardware";
- //tmplog.IPAddress = "192.168.2.82";
- //tmplog.ProcessName = "JsonTestDlg";
- //tmplog.MsgFilesName = "JsonTestDlg";
- //tmplog.LineName = "351";
- //tmplog.FreeText = "hello";
- //tmplog.Version = "2.2200";
- //
- //CString strComment;
- //GetDlgItemText(IDC_EDIT_COMMENT,strComment);
- //tmplog.Comments = strComment;
- //
- ////设置时间
- //SYSTEMTIME localtime;
- //GetLocalTime(&localtime);
- //tmplog.SetTime(localtime);
- //
- ////设置参数列表
- //tmplog.ClearParaList();
- //tmplog.AddPara("name","wanghongwei");
- //tmplog.AddPara("age","34");
- //tmplog.AddPara("city","beijing");
- //
- ////Post方式写日志
- //bool bPostResult = gLogManage.UpdateLogRecord(tmplog);
- //
- ////Send方式写日志
- //bool bSendResult = gLogManage.UpdateLogRecord(tmplog,ST_SEND);
- //-----------------------------调用示例--------------------------------End
- #ifndef _LOGMANAGE_H_
- #define _LOGMANAGE_H_
- #include "AccessBase.h"
- namespace DCAccess
- {
- //--日志--
- struct SLogRecordPo
- {
- string Modules; //(必填)模块ID
- string MsgId; //(必填)消息Id
- string Source; //(必填)来源
- int OccurDate; //(必填)UTC时间与1970年1月1日之间的天数差 设置接口SetTime
- int OccurTime; //(必填)UTC时间与1970年1月1日之间的毫秒差 设置接口SetTime
- string HostName; //(必填)HostName
- string IPAddress; //(可空)IPAddress
- string ProcessName; //(可空)ProcessName
- string MsgFilesName;//(可空)MsgFilesName
- string LineName; //(可空)LineName
- string ParaList; //(可空)ParaList 格式,如:"{P1}={V1};{P2}={V2};{P3}={V3};" 设置接口ClearParaList,AddPara
- string FreeText; //(可空)FreeText
- string Version; //(必填)Version
- string Comments; //(可空)Comments
- SLogRecordPo()
- {
- SYSTEMTIME localtime;
- GetLocalTime(&localtime);
- SetTime(localtime);
- }
- //将当前系统本地时间转换为UTC时间设置到结构中
- //注意:不调用该设置的话,默认设置时间将会将当前PC的本地时间转换为UTC时间设置到结构中
- void SetTime(const SYSTEMTIME& localtime)
- {
- FILETIME localFileTime;
- SystemTimeToFileTime(&localtime,&localFileTime);
- FILETIME utcFileTime;
- LocalFileTimeToFileTime(&localFileTime,&utcFileTime);
- SYSTEMTIME utcSysTime;
- FileTimeToSystemTime(&utcFileTime,&utcSysTime);
- CTimeSpan span = CTime(utcFileTime) - CTime(0);
- OccurDate = span.GetDays();
- OccurTime = (utcSysTime.wHour*3600 + utcSysTime.wMinute*60 + utcSysTime.wSecond)*1000 + utcSysTime.wMilliseconds;
- }
- //清空ParaList
- void ClearParaList()
- {
- ParaList = "";
- }
- //向ParaList中添加参数
- void AddPara(string key,string value)
- {
- CString strtmp;
- strtmp.Format("%s{%s}={%s};",ParaList.c_str(),key.c_str(),value.c_str());
- ParaList = strtmp;
- }
- };
- class DCACCESS_API LogManage : public AccessBase
- {
- private:
- LogManage(void);
- public:
- static LogManage& GetInstance();
- //默认设置
- //InitInstance("127.0.0.1","6630","DIOS.DCService","DIOS.DLL.DCAccessWrapperCPlus");
- //日志
- //仅供内部模块调用,无须登录
- //logRecord 日志信息
- //type 发送方式
- bool UpdateLogRecord(SLogRecordPo& logRecord,SendType type=ST_POST);
- };
- };
- #define gLogManage DCAccess::LogManage::GetInstance()
- #endif
|