From 1d55597edde3bd14c09d64c4cde49c4a68f061b2 Mon Sep 17 00:00:00 2001 From: hyzboy Date: Tue, 24 Dec 2024 23:17:24 +0800 Subject: [PATCH] updated Loginfo/Logger --- inc/hgl/SourceCodeLocation.h | 6 ++- inc/hgl/log/LogInfo.h | 21 +++++---- inc/hgl/log/Logger.h | 90 ------------------------------------ src/Log/LogFile.cpp | 3 -- src/Log/Loginfo.cpp | 8 ++-- 5 files changed, 20 insertions(+), 108 deletions(-) diff --git a/inc/hgl/SourceCodeLocation.h b/inc/hgl/SourceCodeLocation.h index 8587e1b..5c6824e 100644 --- a/inc/hgl/SourceCodeLocation.h +++ b/inc/hgl/SourceCodeLocation.h @@ -1,15 +1,17 @@ #pragma once +#include + namespace hgl { struct SourceCodeLocation { const char * file; ///<源文件 - const char * func; ///<函数 size_t line; ///<行号 + const char * func; ///<函数 }; - #define HGL_SOURCE_CODE_LOCATION __FILE__,__FUNCTION__,__LINE__ + #define HGL_SOURCE_CODE_LOCATION __FILE__,__LINE__,__HGL_FUNC__ #define HGL_SCL_HERE SourceCodeLocation(HGL_SOURCE_CODE_LOCATION) }//namespace hgl diff --git a/inc/hgl/log/LogInfo.h b/inc/hgl/log/LogInfo.h index de00e7c..3f398b5 100644 --- a/inc/hgl/log/LogInfo.h +++ b/inc/hgl/log/LogInfo.h @@ -3,6 +3,7 @@ #include #include +#include namespace hgl { @@ -10,10 +11,12 @@ namespace hgl { enum class LogLevel { - Error=0, //错误,肯定出对话框 - Problem, //问题,默认出对话框 - Hint, //提示,不重要,debug状态默认出对话框 - Log //记录一下 + Verbose, + Info, + Hint, + Warning, + Error, + FatalError, };//enum class LogLevel bool InitLogger(const OSString &app_name); @@ -48,14 +51,14 @@ namespace hgl Log(ll,str+U8_TEXT(">>LogFrom(\"")+U8String((u8char *)filename)+U8_TEXT("\", ")+U8String::numberOf(line)+U8_TEXT(" line,func:\"")+U8String((u8char *)funcname)+U8_TEXT("\")")); } - #define LOG_INFO(str) {Log(LogLevel::Log, str);} + #define LOG_INFO(str) {Log(LogLevel::Info, str);} #define LOG_HINT(str) {Log(LogLevel::Hint, str);} - #define LOG_PROBLEM(str) {Log(LogLevel::Problem, str);} + #define LOG_PROBLEM(str) {Log(LogLevel::Warning, str);} #define LOG_ERROR(str) {Log(LogLevel::Error, str);} - #define RETURN_FALSE {DebugLog(LogLevel::Log,OS_TEXT("return(false)"), __FILE__,__LINE__,__HGL_FUNC__);return(false);} - #define RETURN_ERROR(v) {DebugLog(LogLevel::Log,OS_TEXT("return error(")+OSString::numberOf(v)+OS_TEXT(")"),__FILE__,__LINE__,__HGL_FUNC__);return(v);} - #define RETURN_ERROR_NULL {DebugLog(LogLevel::Log,OS_TEXT("return error(nullptr)"), __FILE__,__LINE__,__HGL_FUNC__);return(nullptr);} + #define RETURN_FALSE {DebugLog(LogLevel::Verbose,OS_TEXT("return(false)"), __FILE__,__LINE__,__HGL_FUNC__);return(false);} + #define RETURN_ERROR(v) {DebugLog(LogLevel::Info, OS_TEXT("return error(")+OSString::numberOf(v)+OS_TEXT(")"),__FILE__,__LINE__,__HGL_FUNC__);return(v);} + #define RETURN_ERROR_NULL {DebugLog(LogLevel::Info, OS_TEXT("return error(nullptr)"), __FILE__,__LINE__,__HGL_FUNC__);return(nullptr);} #define RETURN_BOOL(proc) {if(proc)return(true);RETURN_FALSE} diff --git a/inc/hgl/log/Logger.h b/inc/hgl/log/Logger.h index 97b6a36..5355140 100644 --- a/inc/hgl/log/Logger.h +++ b/inc/hgl/log/Logger.h @@ -31,96 +31,6 @@ namespace hgl };//class Logger }//namespace logger - namespace logger - { - /** - * 日志级别枚举 - */ - enum LOG_LEVEL - { - LL_START=0, ///<日志级别起始定义 - - LL_HOTPOT, ///<性能记录热点 - LL_CODE, ///<代码日志(引擎内部记录) - LL_USER, ///<用户日志(开发人员的日志) - LL_RUN, ///<运行日志(实际使用时的日志) - - LL_END ///<日志级别结束定义 - }; - - /** - * 影响级别 - */ - enum AFFECTOR_LEVEL - { - AL_START=0, - - AL_USER, ///<用户级(无关仅要,正常程序逻辑报错) - AL_FUNC, ///<函数级(当前函数报错) - AL_MODULE, ///<模块级 - AL_FULL, ///<整体级(很严重,只能退出) - - AL_MUST_FIXED, ///<必须修正的代码问题 - - AL_END - }; - - /** - * 日志输出基类 - */ - class LoggerBase - { - protected: - - LOG_LEVEL log_level; - AFFECTOR_LEVEL err_level; - - protected: - - uint32 source_file; ///<源代所在文件ID - uint32 source_line; ///<源代码所在行 - uint32 function; ///<函数ID - HGL_POINTER_UINT object_address; ///<对象地址 - HGL_POINTER_UINT thread_id; ///<线程ID - - public: - };//class LoggerBase - - /** - * 线程日志 - */ - class ThreadLogger - { - - public: - - - };//class ThreadLogger - - /** - * 对象日志 - */ - class ObjectLogger - { - }; - - /** - * 时间追踪日志 - * 针对同一数据记录每一次时间下的数值的日志输出模块 - */ - class TimeLogger - { - }; - - /** - * 图形日志
- * 用于记录碰撞信息,寻路信息,路线跟踪等等 - */ - class GraphicsLogger - { - };// - }//namespace logger - using namespace logger; }//namespace hgl #endif//HGL_LOGGER_INCLUDE diff --git a/src/Log/LogFile.cpp b/src/Log/LogFile.cpp index 6ae00e5..a2e5a17 100644 --- a/src/Log/LogFile.cpp +++ b/src/Log/LogFile.cpp @@ -101,9 +101,6 @@ namespace hgl Logger *CreateLoggerFile(const OSString &pc,LogLevel ll) { - if(llCreate(pc)) diff --git a/src/Log/Loginfo.cpp b/src/Log/Loginfo.cpp index e78ea79..aca320e 100644 --- a/src/Log/Loginfo.cpp +++ b/src/Log/Loginfo.cpp @@ -38,7 +38,7 @@ namespace hgl for(int i=0;iGetLevel()>=level) + if((*log)->GetLevel()<=level) (*log)->Write(str,size); ++log; @@ -73,7 +73,7 @@ namespace hgl OS_TEXT("Current program: ") + cur_program.c_str() + OS_TEXT("\n")+ OS_TEXT("Current path: ") + cur_path.c_str() + OS_TEXT("\n"); - WriteLog(LogLevel::Log,str.c_str(),str.Length()); + WriteLog(LogLevel::Verbose,str.c_str(),str.Length()); return(true); } @@ -207,8 +207,8 @@ namespace hgl */ bool InitLogger(const OSString &app_name) { - AddLogger(CreateLoggerConsole(LogLevel::Log)); - AddLogger(CreateLoggerFile(app_name,LogLevel::Log)); + AddLogger(CreateLoggerConsole(LogLevel::Verbose)); + AddLogger(CreateLoggerFile(app_name,LogLevel::Verbose)); return InitLog(); }