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
|
|
|
};
|
|
|
|
|
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
|
|
|
|
2014-08-12 11:05:04 -04:00
|
|
|
void AttachListener(cListener * a_Listener);
|
|
|
|
void DetachListener(cListener * a_Listener);
|
2014-08-10 14:44:49 -04: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<cListener *> m_LogListeners;
|
2014-08-10 14:44:49 -04:00
|
|
|
|
2014-08-12 11:05:04 -04:00
|
|
|
};
|
2014-08-10 14:44:49 -04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#define LOGWARNING LOGWARN
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|