-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathlogging.h
65 lines (46 loc) · 1.63 KB
/
logging.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
62
63
64
65
#ifndef LOGGING_H_
#define LOGGING_H_
#include <stdint.h>
#include <sstream>
namespace MumbleClient {
namespace logging {
void SetLogLevel(int32_t level);
int32_t GetLogLevel();
typedef int32_t LogSeverity;
const LogSeverity LOG_INFO = 0;
const LogSeverity LOG_WARNING = 1;
const LogSeverity LOG_ERROR = 2;
const LogSeverity LOG_FATAL = 3;
const LogSeverity LOG_NUM_SEVERITIES = 4;
#define MC_LOG_INFO ::MumbleClient::logging::LogMessage(__FILE__, __LINE__, ::MumbleClient::logging::LOG_INFO)
#define MC_LOG_WARNING ::MumbleClient::logging::LogMessage(__FILE__, __LINE__, ::MumbleClient::logging::LOG_WARNING)
#define MC_LOG_ERROR ::MumbleClient::logging::LogMessage(__FILE__, __LINE__, ::MumbleClient::logging::LOG_ERROR)
#define MC_LOG_FATAL ::MumbleClient::logging::LogMessage(__FILE__, __LINE__, ::MumbleClient::logging::LOG_FATAL)
#define LOG(severity) MC_LOG_ ## severity.stream()
#if !defined(NDEBUG)
#define DLOG(severity) MC_LOG_ ## severity.stream()
#else
#define DLOG(severity) true ? 0 : ::MumbleClient::logging::LogMessageVoidify() & LOG(severity)
#endif
class LogMessage {
public:
LogMessage(const char* file, int32_t line);
LogMessage(const char* file, int32_t line, LogSeverity severity);
~LogMessage();
std::ostream& stream() { return stream_; }
private:
void Init(const char* file, int32_t line);
LogSeverity severity_;
std::ostringstream stream_;
std::streamoff message_start_;
LogMessage(const LogMessage&);
void operator=(const LogMessage&);
};
class LogMessageVoidify {
public:
LogMessageVoidify() { }
void operator&(std::ostream&) { }
};
} // namespace logging
} // namespace MumbleClient
#endif // LOGGING_H_