-
Notifications
You must be signed in to change notification settings - Fork 0
/
Logging.h
83 lines (62 loc) · 1.62 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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
/*
* Logging.h
*
* Created on: Dec 10, 2016
* Author: louis
*/
#ifndef LOGGING_H_
#define LOGGING_H_
#include <ostream>
#include <iostream>
#define L_N SLM::Logging::getInstance() << SLM::LoggingLevel::NONE
#define L_I SLM::Logging::getInstance() << SLM::LoggingLevel::INFO
#define L_V SLM::Logging::getInstance() << SLM::LoggingLevel::VERBOSE
#define L_P SLM::Logging::getInstance() << SLM::LoggingLevel::PATTERN
#define L_S SLM::Logging::getInstance() << SLM::LoggingLevel::SUBPATTERN
#define L_A SLM::Logging::getInstance() << SLM::LoggingLevel::ALL
namespace SLM {
enum LoggingLevel { NONE = 0, INFO = 10, VERBOSE = 20, PATTERN = 30, SUBPATTERN = 40, ALL = 100};
class Logging {
public:
static Logging& getInstance()
{
static Logging instance;
return instance;
}
Logging(Logging const&) = delete;
void operator=(Logging const&) = delete;
LoggingLevel get() const;
std::string toString() const;
std::string toString(LoggingLevel level) const;
void set(LoggingLevel level);
void set(const std::string& level);
bool doLog(LoggingLevel currentLevel) const;
template<typename T> Logging& operator<<(const T& stream)
{
if(doLog(coutLevel))
{
std::cout << stream;
}
return *this;
}
typedef std::ostream& (*stream_function)(std::ostream&);
Logging& operator<<(stream_function func)
{
if(doLog(coutLevel))
{
func(std::cout);
}
return *this;
}
Logging& operator<<(LoggingLevel dl)
{
coutLevel = dl;
return *this;
}
private:
LoggingLevel coutLevel = LoggingLevel::NONE;
LoggingLevel loggingLevel = LoggingLevel::NONE;
Logging() {}
};
} /* namespace SLM */
#endif /* LOGGING_H_ */