-
Notifications
You must be signed in to change notification settings - Fork 0
/
Logger.h
91 lines (72 loc) · 1.3 KB
/
Logger.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
84
85
86
87
88
89
90
91
#pragma once
#include <string>
static std::string time()
{
std::string res;
return res;
}
class Logger
{
public:
enum LVL {DEB, WARN, ERR};
Logger(std::ostream& os) :
os_(os),
lvl_(DEB)
{}
Logger(const Logger&) = delete;
Logger operator=(const Logger&) = delete;
void SetLevel(LVL level)
{
lvl_ = level;
}
template <typename T>
void Debug(const T& t)
{
return Debug(t, "");
}
template <typename T, typename ... ARGS>
void Debug(const T& t, ARGS...args)
{
if (lvl_ > DEB) return;
os_ << time() << " DEBUG: " << t << " ";
return Log(args...);
}
template <typename T>
void Warn(const T& t)
{
return Warn(t, "");
}
template <typename T, typename ... ARGS>
void Warn(const T& t, ARGS...args)
{
os_ << time() << " WARNING: " << t << " ";
return Log(args...);
}
template <typename T>
void Error(const T& t)
{
return Error(t, "");
}
template <typename T, typename ... ARGS>
void Error(const T& t, ARGS...args)
{
os_ << time() << " ERROR: " << t << " ";
return Log(args...);
}
private:
template <typename T, typename ... ARGS>
void Log(const T& t, ARGS...args)
{
os_ << t << " ";
return Log(args...);
}
template <typename T>
void Log(const T& t)
{
os_ << t << std::endl;
}
private:
static Logger* instance_;
std::ostream& os_;
LVL lvl_;
};