⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 doctrinelog.cpp

📁 一个模拟动作源码
💻 CPP
字号:
#include "StdAfx.h"
#include "DoctrineLog.h"
#include "DoctrineException.h"

CDoctrineLog::CDoctrineLog()
{
	m_pEntity = NULL;
	m_pfcnLogHandler = NULL;
	m_enumLogLevel = LOG_TRACE;
}

void CDoctrineLog::SetLogHandlerFcn(ENTITY_PTR* pEntity, void* pfcnLogHandler, LOG_LEVEL level /*= LOG_TRACE*/)
{
	m_pEntity			= pEntity;
	m_pfcnLogHandler	= (FcnLogHandler)pfcnLogHandler;
	m_enumLogLevel		= level;
}

void CDoctrineLog::WriteLog(LOG_LEVEL level, string strClass, string strFunc, string strInfo)
{
	if (m_pEntity && m_pfcnLogHandler)
	{
		// Filter logs based on level
		bool bWrite = false;
		switch (m_enumLogLevel)
		{
		case LOG_CRITICALERROR:
			if (LOG_CRITICALERROR == level)
			{
				bWrite = true;
			}
			break;
		case LOG_ERROR:
			if (LOG_CRITICALERROR == level || LOG_ERROR == level)
			{
				bWrite = true;
			}
			break;
		case LOG_WARNING:
			if (LOG_CRITICALERROR == level || LOG_ERROR == level || LOG_WARNING == level)
			{
				bWrite = true;
			}
			break;
		case LOG_INFO:
			if (LOG_CRITICALERROR == level || LOG_ERROR == level || LOG_WARNING == level || LOG_INFO == level)
			{
				bWrite = true;
			}
			break;
		case LOG_TRACE:
			bWrite = true;
			break;
		default:
			bWrite = true;
			break;
		}

		if (bWrite)
		{
			string strMessage = strClass + "::" + strFunc + ": " + strInfo;
			(*m_pfcnLogHandler)(m_pEntity, GetLogLevel(level).c_str(), strMessage.c_str());
		}
	}
	if (LOG_CRITICALERROR == level)
	{
		// If critical error, throw exception
		CDoctrineException exception;
		exception.m_strLogLevel = GetLogLevel(level).c_str();
		exception.m_strClassName = strClass.c_str();
		exception.m_strFunctionName = strFunc.c_str();
		exception.m_strInformation = strInfo.c_str();
		throw exception;
	}
}

string CDoctrineLog::GetLogLevel(LOG_LEVEL level)
{
	string strLevel;

	switch (level)
	{
	case LOG_CRITICALERROR:
		strLevel = "LOG_CRITICALERROR";
		break;
	case LOG_ERROR:
		strLevel = "LOG_ERROR";
		break;
	case LOG_WARNING:
		strLevel = "LOG_WARNING";
		break;
	case LOG_INFO:
		strLevel = "LOG_INFO";
		break;
	case LOG_TRACE:
		strLevel = "LOG_TRACE";
		break;
	default:
		string strLevel = "";
		break;
	}

	return strLevel;
}

⌨️ 快捷键说明

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