CMCore/inc/hgl/log/LogInfo.h

68 lines
2.6 KiB
C
Raw Normal View History

#pragma once
2019-08-19 19:19:58 +08:00
#include<iostream>
#include<source_location>
2019-08-19 19:19:58 +08:00
#include<hgl/CodePage.h>
#include<hgl/log/LogLevel.h>
2019-08-19 19:19:58 +08:00
namespace hgl
{
namespace logger
{
bool InitLogger(const OSString &app_name);
void Log(LogLevel level,const u16char *str,int size);
void Log(LogLevel level,const u8char *str,int size);
2019-08-19 19:19:58 +08:00
inline void Log(LogLevel ll,const U16String &str)
2019-08-19 19:19:58 +08:00
{
Log(ll,str.c_str(),str.Length());
2019-08-19 19:19:58 +08:00
}
inline void Log(LogLevel ll,const U8String &str)
2020-07-07 19:14:42 +08:00
{
Log(ll,str.c_str(),str.Length());
2020-07-07 19:14:42 +08:00
}
#ifdef HGL_SUPPORT_CHAR8_T
inline void Log(LogLevel ll,const AnsiString &str)
{
std::cout<<str.c_str()<<std::endl;
}
#endif//HGL_SUPPORT_CHAR8_T
inline void DebugLog(LogLevel ll,const U16String &str,const std::source_location scl)
2019-08-19 19:19:58 +08:00
{
Log(ll,str+U16_TEXT(">>LogFrom(\"")+
to_u16((u8char *)scl.file_name())+U16_TEXT("\", (")+
U16String::numberOf(scl.line())+U16_TEXT(",")+
U16String::numberOf(scl.column())+U16_TEXT(") ,func:\"")+
to_u16((u8char *)scl.function_name())+U16_TEXT("\")"));
2019-08-19 19:19:58 +08:00
}
inline void DebugLog(LogLevel ll,const U8String &str,const std::source_location scl)
2019-08-19 19:19:58 +08:00
{
Log(ll,str+U8_TEXT(">>LogFrom(\"")+
U8String((u8char *)scl.file_name())+U8_TEXT("\",(")+
U8String::numberOf(scl.line())+U8_TEXT(",")+
U8String::numberOf(scl.column())+U8_TEXT(") ,func:\"")+
U8String((u8char *)scl.function_name())+U8_TEXT("\")"));
2019-08-19 19:19:58 +08:00
}
2024-12-24 23:17:24 +08:00
#define LOG_INFO(str) {Log(LogLevel::Info, str);}
#define LOG_HINT(str) {Log(LogLevel::Hint, str);}
2024-12-24 23:17:24 +08:00
#define LOG_PROBLEM(str) {Log(LogLevel::Warning, str);}
#define LOG_ERROR(str) {Log(LogLevel::Error, str);}
2019-08-19 19:19:58 +08:00
#define RETURN_FALSE {DebugLog(LogLevel::Verbose,OS_TEXT("return(false)"), std::source_location::current());return(false);}
#define RETURN_ERROR(v) {DebugLog(LogLevel::Info, OS_TEXT("return error(")+OSString::numberOf(v)+OS_TEXT(")"),std::source_location::current());return(v);}
#define RETURN_ERROR_NULL {DebugLog(LogLevel::Info, OS_TEXT("return error(nullptr)"), std::source_location::current());return(nullptr);}
2019-08-19 19:19:58 +08:00
#define RETURN_BOOL(proc) {if(proc)return(true);RETURN_FALSE}
#define IF_FALSE_RETURN(str) if(!str)RETURN_FALSE;
}//namespace logger
using namespace logger;
}//namespace hgl