logmediator.cpp

来自「跨操作系统的微型中间件」· C++ 代码 · 共 88 行

CPP
88
字号
#include "LogMacro.h"#include "RunLog.h"#include "ErrLog.h"
#include "LogCreater.h"#include "XMLConfig2.h"extern CLog *g_pRunLog;extern CLog *g_pErrLog;
extern CLog *g_pScheduleLog;/////////////////////////////////////////////////////////////////////////////Interface For C++//如果定义了以下函数, 则最好定义对应的c接口函数, 定义规则是在//这个函数名后加"_For_C"作为新的函数名, 定义之前加上' extern "C" 'void _RunLog(const int nLevel, const int dwModuleID, const char* Desc, const char* File, const int Line){	if(!CCreateLogs::IsInited())		CCreateLogs::Init();	g_pRunLog->SetStatus( SConfigPara::m_RunLogState );		if(g_pRunLog->GetStatus() == 0)		return;#ifndef WIN32	CRunLog *pRunLog = dynamic_cast<CRunLog*>(g_pRunLog);#else	CRunLog *pRunLog = (CRunLog*)g_pRunLog;#endif	if(NULL == pRunLog)		return;	OSMutexLocker cLocker(pRunLog->GetMutex()); //锁管理器, 自动加锁, 自动解锁	if(LOG_SUCCESS != pRunLog->SetItems(nLevel, dwModuleID, Desc, File, Line))	{		return;	}	pRunLog->WriteLog();}void _ErrLog(const int dwModuleID, const int dwErrCode, const char* strDesc, const int dwErrLevel, const char* File, const int Line){	if(!CCreateLogs::IsInited())		CCreateLogs::Init();		g_pErrLog->SetStatus( SConfigPara::m_ErrLogState );		if(g_pErrLog->GetStatus() == 0)		return;#ifndef WIN32	CErrLog *pErrLog = dynamic_cast<CErrLog*>(g_pErrLog);#else	CErrLog *pErrLog = (CErrLog*)g_pErrLog;#endif	if(NULL == pErrLog)		return;		OSMutexLocker cLocker(pErrLog->GetMutex()); //锁管理器, 自动加锁, 自动解锁		if(LOG_SUCCESS != pErrLog->SetItems(dwModuleID, dwErrCode, strDesc, dwErrLevel, File, Line))	{		return;	}	pErrLog->WriteLog();}/////////////////////////////////////////////////////////////////////以下函数是上面函数相对应的C接口函数//////////////////////////////extern "C" void _RunLog_For_C(const int nLevel, const int dwModuleID, const char* Desc, const char* File, const int Line){	_RunLog(nLevel, dwModuleID, Desc, File, Line);}extern "C" void _ErrLog_For_C(const int dwModuleID, const int dwErrCode, const char* strDesc, const int dwErrLevel, const char* File, const int Line){	_ErrLog(dwModuleID, dwErrCode, strDesc, dwErrLevel, File, Line);}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?