Framwork框架日志与配置工具的使用
一。使用设置:
头文件的添加:
..\Framwork\Include\pthread_64;
..\Framwork\CommFramwork\include;
..\Framwork\Utility\Include;
..\Framwork\NetMgr\Include;
..\Framwork\FramworkAp\Include;
..\Framwork\BlockMsg\Include;
..\Framwork\wdInterface\Include;
lib路径的添加:
FramworkAp.lib
Utility.lib
libeay32.lib
ssleay32.lib
BlockMsg.lib
pthreadVC2.lib
CommFramwork.lib
Utility.lib
FramworkAp.lib
NetMgr.lib
wdinterface.lib
二。使用方法
1.LOG的使用
准备工作:
建立配置文件 Config.cfg,拷贝内容:
-------------------------------------------------------------
# -------------------------日志-----------------------------
# device(设备)包括file(文件), console(控制台)及将来扩展的日志主机等
# level(级别)包括E_CRITICAL, E_ERROR, E_WARNING, E_NOTICE, E_SYSINFO, E_PROINFO, E_APPINFO, E_DEBUG
logger.type = common, debug, net
logger.common.device = file
logger.common.level = E_CRITICAL, E_ERROR, E_WARNING, E_NOTICE, E_SYSINFO, E_PROINFO, E_APPINFO, E_DEBUG, E_STATICS
logger.common.path = E:\work\CTPServer\Bin64\log
logger.common.prefix = CTPServer
logger.common.postfix = log
logger.common.num = 6
logger.common.level1 = E_CRITICAL
logger.common.file1 = LogErr
logger.common.level2 = E_ERROR
logger.common.file2 = LogErr
logger.common.level3 = E_WARNING
logger.common.file3 = LogErr
logger.common.level4 = E_PROINFO
logger.common.file4 = LogProInfo
logger.common.level5 = E_STATICS
logger.common.file5 = LogStatics
logger.common.level6 = E_DEBUG
logger.common.file6 = LogDebug
logger.debug.device = console
logger.debug.level = E_CRITICAL, E_ERROR, E_WARNING, E_NOTICE, E_SYSINFO, E_PROINFO, E_APPINFO, E_DEBUG, E_STATICS
logger.net.device = netlog
logger.net.level = E_CRITICAL, E_ERROR, E_WARNING, E_NOTICE, E_SYSINFO, E_PROINFO, E_APPINFO, E_DEBUG, E_STATICS
第一步:添加头文件
#include "Logger.h"
第二步:初始化
CLogger::Instance()->Initial(。。。);
第三步:启动日志
if (CLogger::Instance()->Start() != 0)
return ;
第四步:使用
CRLog(E_DEBUG, "配置初始化成功");
CRLog(E_APPINFO, "配置初始化成功");
2.配置文件的使用
准备工作:
第一步:引入
#include "ConfigImpl.h"
第二步:定义
CConfigImpl* m_pConfig;
第三步:日志初始化
m_pConfig = new CConfigImpl();
第四步:加载配置文件
if (m_pConfig->Load(strPath) != 0)
return ;
第五步:使用配置
m_pConfig->GetProperty(key, value);
例如“用配置来初始化日志”:
if (CLogger::Instance()->Initial(m_pConfig->GetProperties("logger")) != 0)
return ;
第六步:删除
if (0 != m_pConfig)
{
delete m_pConfig;
m_pConfig = nullptr;
}
3.文件共享的消息队列
第一步:引入头文件
#include "XQueue.h"
#include "XQueueIO.h"
第二步:
1.读取模式(进程间通信)
CXQueue xQueue;//定义
do
{
setColor(12,0);
int nRet = xQueue.Open(sXQueName.c_str());//打开
if (!xQueue.IsOpen())
{
string strTmp ="打开共享内存信息队列[";
strTmp += sXQueName;
strTmp += "]失败!10秒后再试!";
//cout << "打开共享内存信息队列[" << sXQueName << "]失败!10秒后再试!" << endl;
Sleep(10000);
}
else
{
break;
}
} while (1);
unsigned int uiBlockSize = 1024;
unsigned int uiXQueLen = 1024;
unsigned int uiBufSize = uiBlockSize*uiXQueLen;
char* pBuf= NULL;
pBuf = new char[uiBufSize];
long lRet = xQueue.Read((LPBYTE)pBuf, &uiBufSize, &nMessageId, NULL, uiTimeout);//读取
if (XQUEUE_ERROR_SUCCESS != lRet)
{
setColor(12);
string strTmp ="共享队列 [";
strTmp += sXQueName;
strTmp += "]没有数据!";
CRLog(E_ERROR,"%s",strTmp.c_str());
continue;
}
setColor(11);
CRLog(E_ERROR,"共享队列[XQueue]读完成");
2.创建模式
例如:创建2个文件共享队列
vector< CXQueueIo<QUOTATION>* > m_vecQueueIo;
//初始创建
unsigned int uiXQueNum = 2;
if (0 == m_pConfig->GetProperty("XQUE_NUM", sTmp))
{
uiXQueNum = strutils::FromString<unsigned int>(sTmp);
if (uiXQueNum > 10)
uiXQueNum = 2;
}
for (unsigned int uiIndex = 1; uiIndex <= uiXQueNum; uiIndex++)
{
string sCfgName = "XQUE" + strutils::ToString<unsigned int>(uiIndex);
CConfig *pCfgWriter;
pCfgWriter = m_pConfig->GetProperties(sCfgName);
if (0 != pCfgWriter && !pCfgWriter->IsEmpty())
{
}
else
{
pCfgWriter = m_pConfig;
}
CRLog(E_APPINFO,"初始化[%s]发布点", sCfgName.c_str());
CXQueueIo<QUOTATION>* pWriter = new CXQueueIo<QUOTATION>();
pWriter->Init(pCfgWriter);//跟配置文件名绑定在一起
m_vecQueueIo.push_back(pWriter);
}
//启动
int nCount = 0;
for (vector< CXQueueIo<QUOTATION>* >::iterator it = m_vecQueueIo.begin(); it != m_vecQueueIo.end(); ++it)
{
nCount++;
if (0 != *it)
{
CRLog(E_APPINFO,"启动[XQUE%d]", nCount);
(*it)->Start();
}
}
//分发给相应队列处理
int uiCount = 0;
string sXQueName,sTmp;
for (vector< CXQueueIo<QUOTATION>* >::iterator it = m_vecQueueIo.begin(); it != m_vecQueueIo.end(); ++it)
{
uiCount++;
if (0 != *it)
{
(*it)->Enque(quo);
sXQueName = "XQUE" + strutils::ToString<unsigned int>(uiCount);
sXQueName +=".XQUE_NAME";
if (0 == m_pConfig->GetProperty(sXQueName,sTmp))
sXQueName = sTmp;
CRLog(E_APPINFO,"共享队列XQueue[%s]写完成",sXQueName.c_str());
}
}//end for
4.看门狗功能
第一步:引入头文件
#include
第二步:定义对象
CMemShareAlive m_oMemShareAlive;
第三步:初始化
m_oMemShareAlive.Bind(E_PROCESS_APP);
第四步:创建对象
if (FALSE == m_oMemShareAlive.Create(sTmp.c_str()))
{
setColor(12,0);
cout << "MemShareAlive.Create fail" << endl;
CRLog(E_ERROR,"%s", sXQueName.c_str());
}
else
{
cout << "MemShareAlive.Create Successfull." << endl;
unsigned int uiProcessID = ::GetCurrentProcessId();
m_oMemShareAlive.IamAlive(uiProcessID);
//m_oMemShareAlive.SetNodeID(uiNodeID);
}
第五步:在节点位置,都添加上语句
m_oMemShareAlive.IamAlive();
第六步:在WatchDog的配置文件上加上监控XX.EXE,就可以自动启动XX.EXE程序
上一篇: IOI2016Day2. Paint