#pragma once #include #include "String.DString.hpp" #define __M_LOG_LOG4CPP__ //----------------------------------------------------------------------------- // mLog 是对 gLogger 的简单封装 // mLog 可以理解为 myLog, 或者 mainLog 的短名称 //----------------------------------------------------------------------------- namespace mLog { extern Log4CPP::Logger * gLogger; inline void NewLine () { if (! gLogger) return; gLogger->NewLine (); } #if 1 //< const char * template inline void Force (const char * fmt, Args && ... args) { if (! gLogger) return; gLogger->Force (fmt, std::forward (args)...); } template inline void Log (const char * fmt, Args && ... args) { if (! gLogger) return; gLogger->Info (fmt, std::forward (args)...); } template inline void Verbose (const char * fmt, Args && ... args) { if (! gLogger) return; gLogger->Verbose (fmt, std::forward (args)...); } template inline void Trace (const char * fmt, Args && ... args) { if (! gLogger) return; gLogger->Trace (fmt, std::forward (args)...); } template inline void Debug (const char * fmt, Args && ... args) { if (! gLogger) return; gLogger->Debug (fmt, std::forward (args)...); } template inline void Info (const char * fmt, Args && ... args) { if (! gLogger) return; gLogger->Info (fmt, std::forward (args)...); } template inline void Notice (const char * fmt, Args && ... args) { if (! gLogger) return; gLogger->Notice (fmt, std::forward (args)...); } template inline void Warn (const char * fmt, Args && ... args) { if (! gLogger) return; gLogger->Warn (fmt, std::forward (args)...); } template inline void Warning (const char * fmt, Args && ... args) { if (! gLogger) return; gLogger->Warn (fmt, std::forward (args)...); } template inline void Error (const char * fmt, Args && ... args) { if (! gLogger) return; gLogger->Error (fmt, std::forward (args)...); } template inline void Fatal (const char * fmt, Args && ... args) { if (! gLogger) return; gLogger->Fatal (fmt, std::forward (args)...); } //> #endif //< StringView template inline void Force (const eSTR::StringView & fmt, Args && ... args) { if (! gLogger) return; gLogger->Force (fmt, std::forward (args)...); } template inline void Log (const eSTR::StringView & fmt, Args && ... args) { if (! gLogger) return; gLogger->Info (fmt, std::forward (args)...); } template inline void Trace (const eSTR::StringView & fmt, Args && ... args) { if (! gLogger) return; gLogger->Trace (fmt, std::forward (args)...); } template inline void Debug (const eSTR::StringView & fmt, Args && ... args) { if (! gLogger) return; gLogger->Debug (fmt, std::forward (args)...); } template inline void Info (const eSTR::StringView & fmt, Args && ... args) { if (! gLogger) return; gLogger->Info (fmt, std::forward (args)...); } template inline void Notice (const eSTR::StringView & fmt, Args && ... args) { if (! gLogger) return; gLogger->Notice (fmt, std::forward (args)...); } template inline void Warn (const eSTR::StringView & fmt, Args && ... args) { if (! gLogger) return; gLogger->Warn (fmt, std::forward (args)...); } template inline void Warning (const eSTR::StringView & fmt, Args && ... args) { if (! gLogger) return; gLogger->Warn (fmt, std::forward (args)...); } template inline void Error (const eSTR::StringView & fmt, Args && ... args) { if (! gLogger) return; gLogger->Error (fmt, std::forward (args)...); } template inline void Fatal (const eSTR::StringView & fmt, Args && ... args) { if (! gLogger) return; gLogger->Fatal (fmt, std::forward (args)...); } //> //< DString template inline void Force (const eSTR::DString & fmt, Args && ... args) { if (! gLogger) return; gLogger->Force (fmt.To (), std::forward (args)...); } template inline void Log (const eSTR::DString & fmt, Args && ... args) { if (! gLogger) return; gLogger->Info (fmt.To (), std::forward (args)...); } template inline void Trace (const eSTR::DString & fmt, Args && ... args) { if (! gLogger) return; gLogger->Trace (fmt.To (), std::forward (args)...); } template inline void Debug (const eSTR::DString & fmt, Args && ... args) { if (! gLogger) return; gLogger->Debug (fmt.To (), std::forward (args)...); } template inline void Info (const eSTR::DString & fmt, Args && ... args) { if (! gLogger) return; gLogger->Info (fmt.To (), std::forward (args)...); } template inline void Notice (const eSTR::DString & fmt, Args && ... args) { if (! gLogger) return; gLogger->Notice (fmt.To (), std::forward (args)...); } template inline void Warn (const eSTR::DString & fmt, Args && ... args) { if (! gLogger) return; gLogger->Warn (fmt.To (), std::forward (args)...); } template inline void Warning (const eSTR::DString & fmt, Args && ... args) { if (! gLogger) return; gLogger->Warn (fmt.To (), std::forward (args)...); } template inline void Error (const eSTR::DString & fmt, Args && ... args) { if (! gLogger) return; gLogger->Error (fmt.To (), std::forward (args)...); } template inline void Fatal (const eSTR::DString & fmt, Args && ... args) { if (! gLogger) return; gLogger->Fatal (fmt.To (), std::forward (args)...); } //> #define FLOG(tmpl,...) Log("{$}@{$}\t"#tmpl, __FUNCTION__,__LINE__,__VA_ARGS__) #define FTRACE(tmpl,...) Trace("{$}@{$}\t"#tmpl, __FUNCTION__,__LINE__,__VA_ARGS__) #define FDEBUG(tmpl,...) Debug("{$}@{$}\t"#tmpl, __FUNCTION__,__LINE__,__VA_ARGS__) #define FINFO(tmpl,...) Info("{$}@{$}\t "#tmpl, __FUNCTION__,__LINE__,__VA_ARGS__) #define FNOTICE(tmpl,...) Notice("{$}@{$}\t"#tmpl, __FUNCTION__,__LINE__,__VA_ARGS__) #define FWARN(tmpl,...) Warn("{$}@{$}\t"#tmpl, __FUNCTION__,__LINE__,__VA_ARGS__) #define FERROR(tmpl,...) Error("{$}@{$}\t"#tmpl, __FUNCTION__,__LINE__,__VA_ARGS__) inline void Flush (const eSTR::StringView & str) { if (! gLogger) return; gLogger->LogNoFormat (Log4CPP::enInfo, str, str.GetLength (), false); } inline void Flush (const eSTR::DString & str) { if (! gLogger) return; gLogger->LogNoFormat (Log4CPP::enInfo, str, str.GetLength (), false); } inline void LogNoFormat (int Level, const eSTR::DString & str, bool bWithLayout = false) { if (! gLogger) return; gLogger->LogNoFormat (Level, str, str.GetLength (), bWithLayout); } inline void LogNoFormat (int Level, const eSTR::StringView & str, bool bWithLayout = false) { if (! gLogger) return; gLogger->LogNoFormat (Level, str, str.GetLength (), bWithLayout); } inline void LogNoFormat (int Level, const char * buf, int len, bool bWithLayout = false) { if (! gLogger) return; gLogger->LogNoFormat (Level, buf, len, bWithLayout); } inline bool Decide (int Level) { if (! gLogger) return false; return (gLogger->Decide (Level)); } inline void Close () { if (! gLogger) return; gLogger->Close (); } inline eSTR::DString ErrorCodeToString (DWORD errorCode) { if (! gLogger) return eSTR::DString (); return gLogger->ErrorCodeToString (errorCode); } inline int CurrentLevel () { if (! gLogger) return 0; return gLogger->GetLevel (); } inline eSTR::DString CurrentLevelName () { if (! gLogger) return eSTR::DString (); return gLogger->LogLevelToString (gLogger->GetLevel ()); } };