diff options
author | tycho <work.tycho@gmail.com> | 2015-08-30 23:57:43 +0200 |
---|---|---|
committer | tycho <work.tycho@gmail.com> | 2015-09-15 17:19:49 +0200 |
commit | 3187dbf0aa0943d9eca0c5c1259f8a8ca549709b (patch) | |
tree | 82d3aaa2905d360779ea472bc3baf91f8539758b /src/Logger.h | |
parent | Merge pull request #2473 from cuberite/APIDumpRename (diff) | |
download | cuberite-3187dbf0aa0943d9eca0c5c1259f8a8ca549709b.tar cuberite-3187dbf0aa0943d9eca0c5c1259f8a8ca549709b.tar.gz cuberite-3187dbf0aa0943d9eca0c5c1259f8a8ca549709b.tar.bz2 cuberite-3187dbf0aa0943d9eca0c5c1259f8a8ca549709b.tar.lz cuberite-3187dbf0aa0943d9eca0c5c1259f8a8ca549709b.tar.xz cuberite-3187dbf0aa0943d9eca0c5c1259f8a8ca549709b.tar.zst cuberite-3187dbf0aa0943d9eca0c5c1259f8a8ca549709b.zip |
Diffstat (limited to 'src/Logger.h')
-rw-r--r-- | src/Logger.h | 59 |
1 files changed, 32 insertions, 27 deletions
diff --git a/src/Logger.h b/src/Logger.h index 176c6e810..a0c2917a9 100644 --- a/src/Logger.h +++ b/src/Logger.h @@ -23,13 +23,35 @@ public: virtual ~cListener(){} }; + class cAttachment + { + public: + + cAttachment(cAttachment && a_other) + : m_listener(a_other.m_listener) + { + } + + ~cAttachment() + { + cLogger::GetInstance().DetachListener(m_listener); + } + + private: + + cListener * m_listener; + + friend class cLogger; + + cAttachment(cListener * a_listener) : m_listener(a_listener) {} + }; + void Log (const char * a_Format, eLogLevel a_LogLevel, va_list a_ArgList) FORMATSTRING(2, 0); /** Logs the simple text message at the specified log level. */ void LogSimple(AString a_Message, eLogLevel a_LogLevel = llRegular); - void AttachListener(cListener * a_Listener); - void DetachListener(cListener * a_Listener); + cAttachment AttachListener(std::unique_ptr<cListener> a_Listener); static cLogger & GetInstance(void); // Must be called before calling GetInstance in a multithreaded context @@ -37,37 +59,20 @@ public: private: cCriticalSection m_CriticalSection; - std::vector<cListener *> m_LogListeners; - -}; - - - - - - -extern void LOG (const char * a_Format, ...) FORMATSTRING(1, 2); -extern void LOGINFO (const char * a_Format, ...) FORMATSTRING(1, 2); -extern void LOGWARN (const char * a_Format, ...) FORMATSTRING(1, 2); -extern void LOGERROR(const char * a_Format, ...) FORMATSTRING(1, 2); - - - - - -// In debug builds, translate LOGD to LOG, otherwise leave it out altogether: -#ifdef _DEBUG - #define LOGD LOG -#else - #define LOGD(...) -#endif // _DEBUG + std::vector<std::unique_ptr<cListener>> m_LogListeners; + void DetachListener(cListener * a_Listener); +}; -#define LOGWARNING LOGWARN +// These declarations are duplicated in globals.h +extern void LOG (const char * a_Format, ...) FORMATSTRING(1, 2); +extern void LOGINFO (const char * a_Format, ...) FORMATSTRING(1, 2); +extern void LOGWARNING(const char * a_Format, ...) FORMATSTRING(1, 2); +extern void LOGERROR (const char * a_Format, ...) FORMATSTRING(1, 2); |