summaryrefslogtreecommitdiffstats
path: root/src/LogDispacher.h
blob: 31b3b3fc190ba5540c677627e3d66c6daccf1003 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85

#pragma once



class cLog;


namespace Logger
{

	enum eLogLevel
	{
		llRegular,
		llInfo,
		llWarning,
		llError,
	};

	class cLogDispacher;

	// Must be called before calling GetInstance in a multithreaded context
	void InitiateMultithreading();
	
	cLogDispacher & GetInstance(void);
	
	class cLoggerListener
	{
		public:
		virtual void Log(AString a_Message, eLogLevel a_LogLevel) = 0;
		
		virtual ~cLoggerListener(){}
	};

	class cLogDispacher
	{
	public:

		void Log  (const char * a_Format, Logger::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, Logger::eLogLevel a_LogLevel = Logger::llRegular);
	
		void AttachListener(Logger::cLoggerListener * a_Listener);
		void DetachListener(Logger::cLoggerListener * a_Listener);

	private:
	
		cCriticalSection m_CriticalSection;
		std::vector<Logger::cLoggerListener *> 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





#define LOGWARNING LOGWARN