2014-08-10 14:44:49 -04:00
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
|
2014-08-12 11:05:04 -04:00
|
|
|
class cLogger
|
2014-08-10 14:44:49 -04:00
|
|
|
{
|
2014-08-12 11:05:04 -04:00
|
|
|
public:
|
2014-08-10 14:44:49 -04:00
|
|
|
|
|
|
|
enum eLogLevel
|
|
|
|
{
|
|
|
|
llRegular,
|
|
|
|
llInfo,
|
|
|
|
llWarning,
|
|
|
|
llError,
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2014-08-12 11:05:04 -04:00
|
|
|
class cListener
|
2014-08-10 14:44:49 -04:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
virtual void Log(AString a_Message, eLogLevel a_LogLevel) = 0;
|
2014-08-12 11:05:04 -04:00
|
|
|
|
|
|
|
virtual ~cListener(){}
|
2014-08-10 14:44:49 -04:00
|
|
|
};
|
|
|
|
|
2015-08-30 17:57:43 -04:00
|
|
|
class cAttachment
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
2017-04-01 11:28:42 -04:00
|
|
|
cAttachment() : m_listener(nullptr) {}
|
2015-08-30 17:57:43 -04:00
|
|
|
cAttachment(cAttachment && a_other)
|
|
|
|
: m_listener(a_other.m_listener)
|
|
|
|
{
|
2017-04-01 11:28:42 -04:00
|
|
|
a_other.m_listener = nullptr;
|
2015-08-30 17:57:43 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
~cAttachment()
|
|
|
|
{
|
2017-04-01 11:28:42 -04:00
|
|
|
if (m_listener != nullptr)
|
|
|
|
{
|
|
|
|
cLogger::GetInstance().DetachListener(m_listener);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
cAttachment & operator=(cAttachment && a_other)
|
|
|
|
{
|
|
|
|
m_listener = a_other.m_listener;
|
|
|
|
a_other.m_listener = nullptr;
|
|
|
|
return *this;
|
2015-08-30 17:57:43 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
|
|
|
cListener * m_listener;
|
|
|
|
|
|
|
|
friend class cLogger;
|
|
|
|
|
|
|
|
cAttachment(cListener * a_listener) : m_listener(a_listener) {}
|
|
|
|
};
|
|
|
|
|
2014-08-12 11:05:04 -04:00
|
|
|
void Log (const char * a_Format, eLogLevel a_LogLevel, va_list a_ArgList) FORMATSTRING(2, 0);
|
2014-08-10 14:44:49 -04:00
|
|
|
|
2014-08-12 11:05:04 -04:00
|
|
|
/** Logs the simple text message at the specified log level. */
|
|
|
|
void LogSimple(AString a_Message, eLogLevel a_LogLevel = llRegular);
|
2014-08-10 14:44:49 -04:00
|
|
|
|
2015-08-30 17:57:43 -04:00
|
|
|
cAttachment AttachListener(std::unique_ptr<cListener> a_Listener);
|
2016-02-05 16:45:45 -05:00
|
|
|
|
2014-08-12 11:05:04 -04:00
|
|
|
static cLogger & GetInstance(void);
|
|
|
|
// Must be called before calling GetInstance in a multithreaded context
|
|
|
|
static void InitiateMultithreading();
|
|
|
|
private:
|
2014-08-10 14:44:49 -04:00
|
|
|
|
2014-08-12 11:05:04 -04:00
|
|
|
cCriticalSection m_CriticalSection;
|
2015-08-30 17:57:43 -04:00
|
|
|
std::vector<std::unique_ptr<cListener>> m_LogListeners;
|
2014-08-10 14:44:49 -04:00
|
|
|
|
2015-08-30 17:57:43 -04:00
|
|
|
void DetachListener(cListener * a_Listener);
|
2014-08-10 14:44:49 -04:00
|
|
|
|
2015-08-30 17:57:43 -04:00
|
|
|
};
|
2014-08-10 14:44:49 -04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2015-08-30 17:57:43 -04:00
|
|
|
// 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);
|
2014-08-10 14:44:49 -04:00
|
|
|
|
|
|
|
|
|
|
|
|