-
Notifications
You must be signed in to change notification settings - Fork 0
/
log.h
46 lines (36 loc) · 850 Bytes
/
log.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
#ifndef CPRINTF_LOG_H
#define CPRINTF_LOG_H
#include <iostream>
namespace log {
enum log_level_t {
LOG_NONE,
LOG_ERROR,
LOG_WARN,
LOG_INFO,
LOG_DEBUG,
LOG_ALL
};
extern void set_log_level(const char *level);
extern log_level_t curr_log_level(void);
class log_stream {
const log_level_t level;
public:
log_stream(log_level_t l) : level(l) {}
template <typename T> const log_stream& operator<<(const T& v) const
{
if (curr_log_level() >= level)
std::cerr << v;
return *this;
}
typedef std::basic_ostream<char, std::char_traits<char>> std_stream;
typedef std_stream& (*std_manip)(std_stream&);
const log_stream& operator<<(std_manip manip) const
{
if (curr_log_level() >= level)
manip(std::cerr);
return *this;
}
};
extern log_stream err, warn, info, debug, all;
}; /* namespace log */
#endif /* CPRINTF_LOG_H */