Append a new LogOutput class, it's style like Java on Android.
This commit is contained in:
parent
1d55597edd
commit
77a3a9d26e
72
inc/hgl/log/Log.h
Normal file
72
inc/hgl/log/Log.h
Normal file
@ -0,0 +1,72 @@
|
||||
#pragma once
|
||||
|
||||
#include<hgl/platform/Platform.h>
|
||||
#include<hgl/type/String.h>
|
||||
#include<hgl/SourceCodeLocation.h>
|
||||
#include<hgl/log/LogInfo.h>
|
||||
#include<cstdio>
|
||||
#include<cwchar>
|
||||
#include<cstdarg>
|
||||
|
||||
namespace hgl
|
||||
{
|
||||
constexpr const size_t LOG_TMP_BUFFER_SIZE=4096;
|
||||
|
||||
/**
|
||||
* Android风格的日志输出类
|
||||
*/
|
||||
class LogOutput
|
||||
{
|
||||
char tmp_fmt [LOG_TMP_BUFFER_SIZE];
|
||||
u8char tmp_fmt_u8 [LOG_TMP_BUFFER_SIZE];
|
||||
u16char tmp_fmt_u16 [LOG_TMP_BUFFER_SIZE];
|
||||
|
||||
public:
|
||||
|
||||
LogOutput()=default;
|
||||
virtual ~LogOutput()=default;
|
||||
|
||||
public:
|
||||
|
||||
void output(LogLevel level,const char * str,const int len){logger::Log(level,(u8char *)str,len);}
|
||||
void output(LogLevel level,const u8char * str,const int len){logger::Log(level,(u8char *)str,len);}
|
||||
void output(LogLevel level,const u16char * str,const int len){logger::Log(level,(u16char *)str,len);}
|
||||
|
||||
#define DEFINE_LOG_OUTPUT_CHAR(ch,level) \
|
||||
\
|
||||
void ch(const char * str,const int len ){output(LogLevel::level, str,len);} \
|
||||
void ch(const char * str ){ch(str,strlen(str));} \
|
||||
void ch(const AnsiString & str ){ch(str.c_str(),str.GetLength());} \
|
||||
void ch(const AnsiStringView & sv ){ch(sv.c_str(),sv.GetLength());}
|
||||
|
||||
#define DEFINE_LOG_OUTPUT_CHAR8(ch,level) \
|
||||
\
|
||||
void ch(const u8char * str,const int len ){output(LogLevel::level, str,len);} \
|
||||
void ch(const u8char * str ){ch(str,strlen(str));} \
|
||||
void ch(const U8String & str ){ch(str.c_str(),str.GetLength());} \
|
||||
void ch(const U8StringView &sv ){ch(sv.c_str(),sv.GetLength());}
|
||||
|
||||
#define DEFINE_LOG_OUTPUT_CHAR16(ch,level) \
|
||||
\
|
||||
void ch(const u16char * str,const int len ){output(LogLevel::level, str,len);} \
|
||||
void ch(const u16char * str ){ch(str,strlen(str));} \
|
||||
void ch(const U16String & str ){ch(str.c_str(),str.GetLength());} \
|
||||
void ch(const U16StringView &sv ){ch(sv.c_str(),sv.GetLength());}
|
||||
|
||||
#ifdef HGL_SUPPORT_CHAR8_T
|
||||
#define DEFINE_LOG_OUTPUT(ch,level) DEFINE_LOG_OUTPUT_CHAR(ch,level) \
|
||||
DEFINE_LOG_OUTPUT_CHAR8(ch,level) \
|
||||
DEFINE_LOG_OUTPUT_CHAR16(ch,level)
|
||||
#else
|
||||
#define DEFINE_LOG_OUTPUT(ch,level) DEFINE_LOG_OUTPUT_CHAR(ch,level) \
|
||||
DEFINE_LOG_OUTPUT_CHAR16(ch,level)
|
||||
#endif//HGL_SUPPORT_CHAR8_T
|
||||
|
||||
DEFINE_LOG_OUTPUT(v,Verbose)
|
||||
DEFINE_LOG_OUTPUT(i,Info)
|
||||
DEFINE_LOG_OUTPUT(h,Hint)
|
||||
DEFINE_LOG_OUTPUT(w,Warning)
|
||||
DEFINE_LOG_OUTPUT(e,Error)
|
||||
DEFINE_LOG_OUTPUT(fe,FatalError)
|
||||
};//class LogOutput
|
||||
}//namespace hgl
|
@ -4,21 +4,12 @@
|
||||
#include<iostream>
|
||||
#include<hgl/CodePage.h>
|
||||
#include<hgl/SourceCodeLocation.h>
|
||||
#include<hgl/log/LogLevel.h>
|
||||
|
||||
namespace hgl
|
||||
{
|
||||
namespace logger
|
||||
{
|
||||
enum class LogLevel
|
||||
{
|
||||
Verbose,
|
||||
Info,
|
||||
Hint,
|
||||
Warning,
|
||||
Error,
|
||||
FatalError,
|
||||
};//enum class LogLevel
|
||||
|
||||
bool InitLogger(const OSString &app_name);
|
||||
|
||||
void Log(LogLevel level,const u16char *str,int size);
|
||||
|
14
inc/hgl/log/LogLevel.h
Normal file
14
inc/hgl/log/LogLevel.h
Normal file
@ -0,0 +1,14 @@
|
||||
#pragma once
|
||||
|
||||
namespace hgl
|
||||
{
|
||||
enum class LogLevel
|
||||
{
|
||||
Verbose,
|
||||
Info,
|
||||
Hint,
|
||||
Warning,
|
||||
Error,
|
||||
FatalError,
|
||||
};//enum class LogLevel
|
||||
}//namespace hgl
|
@ -46,7 +46,9 @@ namespace hgl
|
||||
|
||||
~StringView()=default;
|
||||
|
||||
const char *c_str()const{return str_data;}
|
||||
operator const T *()const{return str_data;}
|
||||
|
||||
const T *c_str()const{return str_data;}
|
||||
const int length()const{return str_length;}
|
||||
const int GetLength()const{return str_length;}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user