-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlogger.h
80 lines (66 loc) · 1.43 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
#pragma once
#include "mysakLib.h"
#include "types.h"
#if defined INTERACTIVE && !defined _WIN
# include <termios.h>
#endif
namespace MLib
{
const unsigned LOG_error = 0;
const unsigned LOG_warning = 1;
const unsigned LOG_info = 2;
const unsigned LOG_verbose = 3;
const unsigned LOG_debug = 4;
class Log
{
private:
static void writeTypeString(unsigned type)
{
switch (type) {
case LOG_error:
MysakLib::INSTANCE.logfile << "[ERROR] ";
break;
case LOG_warning:
MysakLib::INSTANCE.logfile << "[WARN] ";
break;
case LOG_info:
MysakLib::INSTANCE.logfile << "[INFO] ";
break;
case LOG_verbose:
MysakLib::INSTANCE.logfile << "[VERB] ";
break;
case LOG_debug:
MysakLib::INSTANCE.logfile << "[DEBUG] ";
break;
default:
MysakLib::INSTANCE.logfile << "[?????] ";
break;
}
}
unsigned level;
public:
Log() :
Log(LOG_info)
{
}
Log(unsigned type) :
Log(type, false)
{
}
Log(unsigned type, bool internal);
~Log();
template <typename T>
Log& operator<<(const T& msg)
{
if (level <= MysakLib::INSTANCE.loglevel)
MysakLib::INSTANCE.logfile << msg;
return *this;
}
};
} // namespace MLib
#define LOG_ERR ::MLib::Log(::MLib::LOG_error)
#define LOG_WARN ::MLib::Log(::MLib::LOG_warning)
#define LOG_INFO ::MLib::Log(::MLib::LOG_info)
#define LOG_VERB ::MLib::Log(::MLib::LOG_verbose)
#define LOG_DEBUG ::MLib::Log(::MLib::LOG_debug)
#define LOG ::MLib::Log()