diff options
author | Mattes D <github@xoft.cz> | 2015-09-16 09:12:56 +0200 |
---|---|---|
committer | Mattes D <github@xoft.cz> | 2015-09-16 09:12:56 +0200 |
commit | d041057da239d6dca02306849bd62973f3a51c62 (patch) | |
tree | 82d3aaa2905d360779ea472bc3baf91f8539758b /src/Logger.h | |
parent | Merge pull request #2473 from cuberite/APIDumpRename (diff) | |
parent | Increase robustness of the logging subsystem (diff) | |
download | cuberite-d041057da239d6dca02306849bd62973f3a51c62.tar cuberite-d041057da239d6dca02306849bd62973f3a51c62.tar.gz cuberite-d041057da239d6dca02306849bd62973f3a51c62.tar.bz2 cuberite-d041057da239d6dca02306849bd62973f3a51c62.tar.lz cuberite-d041057da239d6dca02306849bd62973f3a51c62.tar.xz cuberite-d041057da239d6dca02306849bd62973f3a51c62.tar.zst cuberite-d041057da239d6dca02306849bd62973f3a51c62.zip |
Diffstat (limited to '')
-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); |