summaryrefslogtreecommitdiffstats
path: root/src/Logger.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/Logger.h')
-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);