-
Notifications
You must be signed in to change notification settings - Fork 2
/
logger.h
61 lines (43 loc) · 1.17 KB
/
logger.h
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
#ifndef __LOGGER_H__
#define __LOGGER_H__
namespace zhmu {
namespace snippets {
class LoggingSystem;
//! \brief Implements a logging producer
class Logger {
friend class LoggingSystem;
public:
//! \brief Enables logging
void Enable() { m_Enabled = true; }
//! \brief Disables logging
void Disable() { m_Enabled = false; }
/* Functions below are intended to be used by the LOG() macro */
//! \brief Is the logger enabled?
bool _IsEnabled() const { return m_Enabled; }
//! \brief Retrieve the logger name
const char* GetName() const { return m_Name; }
//! \brief Performs logging
void _Log(const char* fmt, ...);
protected:
Logger() = delete;
Logger(const Logger& oLogger) = delete;
/*! \brief Constructor
*
* This is only to be used by the LoggingSystem
*/
Logger(LoggingSystem& oSystem, const char* name);
//! \brief Destroys the logger - note that the LoggingSystem is owner of each Logger
~Logger();
private:
//! \brief Logger name
char* m_Name;
//! \brief Enabled state
bool m_Enabled;
//! \brief Logging system we belong to
LoggingSystem& m_System;
};
#define LOG(l, a...) \
(l)->_IsEnabled() ? (l)->_Log(a) : (void)0
}
}
#endif /* __LOGGER_H__ */