123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319 |
- #pragma once
- #include <assert.h>
- #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 <typename... Args>
- inline void Force (const char * fmt, Args && ... args)
- {
- if (! gLogger) return;
- gLogger->Force (fmt, std::forward <Args> (args)...);
- }
- template <typename... Args>
- inline void Log (const char * fmt, Args && ... args)
- {
- if (! gLogger) return;
- gLogger->Info (fmt, std::forward <Args> (args)...);
- }
- template <typename... Args>
- inline void Verbose (const char * fmt, Args && ... args)
- {
- if (! gLogger) return;
- gLogger->Verbose (fmt, std::forward <Args> (args)...);
- }
- template <typename... Args>
- inline void Trace (const char * fmt, Args && ... args)
- {
- if (! gLogger) return;
- gLogger->Trace (fmt, std::forward <Args> (args)...);
- }
- template <typename... Args>
- inline void Debug (const char * fmt, Args && ... args)
- {
- if (! gLogger) return;
- gLogger->Debug (fmt, std::forward <Args> (args)...);
- }
- template <typename... Args>
- inline void Info (const char * fmt, Args && ... args)
- {
- if (! gLogger) return;
- gLogger->Info (fmt, std::forward <Args> (args)...);
- }
- template <typename... Args>
- inline void Notice (const char * fmt, Args && ... args)
- {
- if (! gLogger) return;
- gLogger->Notice (fmt, std::forward <Args> (args)...);
- }
- template <typename... Args>
- inline void Warn (const char * fmt, Args && ... args)
- {
- if (! gLogger) return;
- gLogger->Warn (fmt, std::forward <Args> (args)...);
- }
- template <typename... Args>
- inline void Warning (const char * fmt, Args && ... args)
- {
- if (! gLogger) return;
- gLogger->Warn (fmt, std::forward <Args> (args)...);
- }
- template <typename... Args>
- inline void Error (const char * fmt, Args && ... args)
- {
- if (! gLogger) return;
- gLogger->Error (fmt, std::forward <Args> (args)...);
- }
- template <typename... Args>
- inline void Fatal (const char * fmt, Args && ... args)
- {
- if (! gLogger) return;
- gLogger->Fatal (fmt, std::forward <Args> (args)...);
- }
- //>
- #endif
- //< StringView
- template <typename... Args>
- inline void Force (const eSTR::StringView & fmt, Args && ... args)
- {
- if (! gLogger) return;
- gLogger->Force (fmt, std::forward <Args> (args)...);
- }
- template <typename... Args>
- inline void Log (const eSTR::StringView & fmt, Args && ... args)
- {
- if (! gLogger) return;
- gLogger->Info (fmt, std::forward <Args> (args)...);
- }
- template <typename... Args>
- inline void Trace (const eSTR::StringView & fmt, Args && ... args)
- {
- if (! gLogger) return;
- gLogger->Trace (fmt, std::forward <Args> (args)...);
- }
- template <typename... Args>
- inline void Debug (const eSTR::StringView & fmt, Args && ... args)
- {
- if (! gLogger) return;
- gLogger->Debug (fmt, std::forward <Args> (args)...);
- }
- template <typename... Args>
- inline void Info (const eSTR::StringView & fmt, Args && ... args)
- {
- if (! gLogger) return;
- gLogger->Info (fmt, std::forward <Args> (args)...);
- }
- template <typename... Args>
- inline void Notice (const eSTR::StringView & fmt, Args && ... args)
- {
- if (! gLogger) return;
- gLogger->Notice (fmt, std::forward <Args> (args)...);
- }
- template <typename... Args>
- inline void Warn (const eSTR::StringView & fmt, Args && ... args)
- {
- if (! gLogger) return;
- gLogger->Warn (fmt, std::forward <Args> (args)...);
- }
- template <typename... Args>
- inline void Warning (const eSTR::StringView & fmt, Args && ... args)
- {
- if (! gLogger) return;
- gLogger->Warn (fmt, std::forward <Args> (args)...);
- }
- template <typename... Args>
- inline void Error (const eSTR::StringView & fmt, Args && ... args)
- {
- if (! gLogger) return;
- gLogger->Error (fmt, std::forward <Args> (args)...);
- }
- template <typename... Args>
- inline void Fatal (const eSTR::StringView & fmt, Args && ... args)
- {
- if (! gLogger) return;
- gLogger->Fatal (fmt, std::forward <Args> (args)...);
- }
- //>
- //< DString
- template <typename... Args>
- inline void Force (const eSTR::DString & fmt, Args && ... args)
- {
- if (! gLogger) return;
- gLogger->Force (fmt.To <eSTR::StringView> (), std::forward <Args> (args)...);
- }
- template <typename... Args>
- inline void Log (const eSTR::DString & fmt, Args && ... args)
- {
- if (! gLogger) return;
- gLogger->Info (fmt.To <eSTR::StringView> (), std::forward <Args> (args)...);
- }
- template <typename... Args>
- inline void Trace (const eSTR::DString & fmt, Args && ... args)
- {
- if (! gLogger) return;
- gLogger->Trace (fmt.To <eSTR::StringView> (), std::forward <Args> (args)...);
- }
- template <typename... Args>
- inline void Debug (const eSTR::DString & fmt, Args && ... args)
- {
- if (! gLogger) return;
- gLogger->Debug (fmt.To <eSTR::StringView> (), std::forward <Args> (args)...);
- }
- template <typename... Args>
- inline void Info (const eSTR::DString & fmt, Args && ... args)
- {
- if (! gLogger) return;
- gLogger->Info (fmt.To <eSTR::StringView> (), std::forward <Args> (args)...);
- }
- template <typename... Args>
- inline void Notice (const eSTR::DString & fmt, Args && ... args)
- {
- if (! gLogger) return;
- gLogger->Notice (fmt.To <eSTR::StringView> (), std::forward <Args> (args)...);
- }
- template <typename... Args>
- inline void Warn (const eSTR::DString & fmt, Args && ... args)
- {
- if (! gLogger) return;
- gLogger->Warn (fmt.To <eSTR::StringView> (), std::forward <Args> (args)...);
- }
- template <typename... Args>
- inline void Warning (const eSTR::DString & fmt, Args && ... args)
- {
- if (! gLogger) return;
- gLogger->Warn (fmt.To <eSTR::StringView> (), std::forward <Args> (args)...);
- }
- template <typename... Args>
- inline void Error (const eSTR::DString & fmt, Args && ... args)
- {
- if (! gLogger) return;
- gLogger->Error (fmt.To <eSTR::StringView> (), std::forward <Args> (args)...);
- }
- template <typename... Args>
- inline void Fatal (const eSTR::DString & fmt, Args && ... args)
- {
- if (! gLogger) return;
- gLogger->Fatal (fmt.To <eSTR::StringView> (), std::forward <Args> (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 ());
- }
- };
|