summaryrefslogtreecommitdiffstats
path: root/src/Logger.h
diff options
context:
space:
mode:
authorelectromatter <electromatter@gmail.com>2015-09-22 04:44:34 +0200
committerelectromatter <electromatter@gmail.com>2015-09-22 04:44:34 +0200
commita24cc0184343416eed86b208d8a2aff2b5c0892c (patch)
tree04ced91aa4a70b4c6e033fac4a2fc2e2ea206205 /src/Logger.h
parentadded bungeecord support for protocol18x (diff)
parentMerge pull request #2488 from cuberite/ChatFlag (diff)
downloadcuberite-a24cc0184343416eed86b208d8a2aff2b5c0892c.tar
cuberite-a24cc0184343416eed86b208d8a2aff2b5c0892c.tar.gz
cuberite-a24cc0184343416eed86b208d8a2aff2b5c0892c.tar.bz2
cuberite-a24cc0184343416eed86b208d8a2aff2b5c0892c.tar.lz
cuberite-a24cc0184343416eed86b208d8a2aff2b5c0892c.tar.xz
cuberite-a24cc0184343416eed86b208d8a2aff2b5c0892c.tar.zst
cuberite-a24cc0184343416eed86b208d8a2aff2b5c0892c.zip
Diffstat (limited to '')
-rw-r--r--src/Logger.h59
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);