updated Loginfo/Logger

This commit is contained in:
2024-12-24 23:17:24 +08:00
parent e416162a1e
commit 1d55597edd
5 changed files with 20 additions and 108 deletions

View File

@@ -1,15 +1,17 @@
#pragma once #pragma once
#include<hgl/platform/Platform.h>
namespace hgl namespace hgl
{ {
struct SourceCodeLocation struct SourceCodeLocation
{ {
const char * file; ///<源文件 const char * file; ///<源文件
const char * func; ///<函数
size_t line; ///<行号 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) #define HGL_SCL_HERE SourceCodeLocation(HGL_SOURCE_CODE_LOCATION)
}//namespace hgl }//namespace hgl

View File

@@ -3,6 +3,7 @@
#include<iostream> #include<iostream>
#include<hgl/CodePage.h> #include<hgl/CodePage.h>
#include<hgl/SourceCodeLocation.h>
namespace hgl namespace hgl
{ {
@@ -10,10 +11,12 @@ namespace hgl
{ {
enum class LogLevel enum class LogLevel
{ {
Error=0, //错误,肯定出对话框 Verbose,
Problem, //问题,默认出对话框 Info,
Hint, //提示不重要debug状态默认出对话框 Hint,
Log //记录一下 Warning,
Error,
FatalError,
};//enum class LogLevel };//enum class LogLevel
bool InitLogger(const OSString &app_name); 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("\")")); 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_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 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_FALSE {DebugLog(LogLevel::Verbose,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(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::Log,OS_TEXT("return error(nullptr)"), __FILE__,__LINE__,__HGL_FUNC__);return(nullptr);} #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} #define RETURN_BOOL(proc) {if(proc)return(true);RETURN_FALSE}

View File

@@ -31,96 +31,6 @@ namespace hgl
};//class Logger };//class Logger
}//namespace 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
{
};
/**
* 图形日志<br>
* 用于记录碰撞信息,寻路信息,路线跟踪等等
*/
class GraphicsLogger
{
};//
}//namespace logger
using namespace logger; using namespace logger;
}//namespace hgl }//namespace hgl
#endif//HGL_LOGGER_INCLUDE #endif//HGL_LOGGER_INCLUDE

View File

@@ -101,9 +101,6 @@ namespace hgl
Logger *CreateLoggerFile(const OSString &pc,LogLevel ll) Logger *CreateLoggerFile(const OSString &pc,LogLevel ll)
{ {
if(ll<LogLevel::Error)
return(nullptr);
LogFile *lf=new LogFile(ll); LogFile *lf=new LogFile(ll);
if(lf->Create(pc)) if(lf->Create(pc))

View File

@@ -38,7 +38,7 @@ namespace hgl
for(int i=0;i<n;i++) for(int i=0;i<n;i++)
{ {
if((*log)->GetLevel()>=level) if((*log)->GetLevel()<=level)
(*log)->Write(str,size); (*log)->Write(str,size);
++log; ++log;
@@ -73,7 +73,7 @@ namespace hgl
OS_TEXT("Current program: ") + cur_program.c_str() + OS_TEXT("\n")+ OS_TEXT("Current program: ") + cur_program.c_str() + OS_TEXT("\n")+
OS_TEXT("Current path: ") + cur_path.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); return(true);
} }
@@ -207,8 +207,8 @@ namespace hgl
*/ */
bool InitLogger(const OSString &app_name) bool InitLogger(const OSString &app_name)
{ {
AddLogger(CreateLoggerConsole(LogLevel::Log)); AddLogger(CreateLoggerConsole(LogLevel::Verbose));
AddLogger(CreateLoggerFile(app_name,LogLevel::Log)); AddLogger(CreateLoggerFile(app_name,LogLevel::Verbose));
return InitLog(); return InitLog();
} }