-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathlogging_dummy.hpp
64 lines (54 loc) · 1.42 KB
/
logging_dummy.hpp
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
#ifndef LOGGING_DUMMY_HPP
#define LOGGING_DUMMY_HPP
// logging_dummy replaces logging.hpp for compilers that don't support
#include <iostream>
#include <stdio.h>
#include <string>
#define DEBUG 0
#define INFO 1
#define WARNING 2
#define ERROR 3
#define FATAL 4
#ifndef LOGLEVEL
#define LOGLEVEL DEBUG
#endif
#define _INITIALIZE_EASYLOGGINGPP
class Log {
public:
bool operator&(std::ostream& stream) {
stream << std::endl;
return true;
}
};
inline std::string log_level_to_str(const int log_level) {
std::string str = "";
switch(log_level) {
case DEBUG:
str = "[DEBUG]";
break;
case INFO:
str = "[INFO]";
break;
case WARNING:
str = "[WARNING]";
break;
case ERROR:
str = "[ERROR]";
break;
case FATAL:
str = "[FATAL]";
break;
default:
break;
}
return str;
}
/* If the minimum log level requirement is satisfied then prints the log
message. This works because the & operator has lower precedence than the
<< operator, therefore the stream output is evaluated before the Log
class is initialised. */
#define LOG(log_level) log_level >= LOGLEVEL && \
Log() & std::cerr << \
log_level_to_str(log_level) << \
__FILE__ << ':' << __LINE__ << ": "
#endif