1
0
cuberite-2a/src/Logger.h

79 lines
1.5 KiB
C
Raw Normal View History

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
};
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) {}
};
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
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;
std::vector<std::unique_ptr<cListener>> m_LogListeners;
2014-08-10 14:44:49 -04:00
void DetachListener(cListener * a_Listener);
2014-08-10 14:44:49 -04:00
};
2014-08-10 14:44:49 -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