-
Notifications
You must be signed in to change notification settings - Fork 229
/
log.h
42 lines (32 loc) · 811 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
#ifndef LOG_H
#define LOG_H
#include <iostream>
#include <string>
class Logger {
public:
enum Level { SILENT = 0, ERROR = 1, INFO = 3, DEBUG = 4 };
Level level;
static Level log_level;
Logger(Level _level): level(_level) {}
template<class T> Logger &operator<<(const T &msg) {
if(level <= Logger::log_level)
std::cout << msg;
return *this;
}
// define an operator<< to take in std::endl
typedef std::basic_ostream<char, std::char_traits<char> > CoutType;
typedef CoutType& (*StandardEndLine)(CoutType&);
Logger& operator<<(StandardEndLine manip) {
if(level <= Logger::log_level)
std::cout << std::endl;
return *this;
}
};
class Log {
public:
static Logger error;
static Logger info;
static Logger debug;
static void flush() { std::cout << std::flush; }
};
#endif // LOG_H