forked from altmp/altv-js-module
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Log.h
109 lines (95 loc) · 2.01 KB
/
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
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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
#pragma once
#include <sstream>
#include "cpp-sdk/ICore.h"
class Log
{
std::stringstream buf;
typedef Log& (*LogFn)(Log&);
static Log* _Instance;
enum Type
{
INFO,
DEBUG,
WARNING,
ERR,
COLORED
} type = INFO;
Log() = default;
public:
Log(const Log&) = delete;
Log(Log&&) = delete;
Log& operator=(const Log&) = delete;
template<class T>
Log& Put(const T& val)
{
buf << val;
return *this;
}
#if __cplusplus >= 202002L
Log& Put(const char8_t* val)
{
buf << (const char*)val;
return *this;
}
#endif // __cplusplus
Log& Put(LogFn val)
{
return val(*this);
}
Log& SetType(Type _type)
{
type = _type;
return *this;
}
template<class T>
Log& operator<<(const T& val)
{
return Put(val);
}
static constexpr struct Log_Info
{
template<class T>
Log& operator<<(const T& val) const
{
return Instance().SetType(INFO).Put(val);
}
} Info{};
static constexpr struct Log_Debug
{
template<class T>
Log& operator<<(const T& val) const
{
return Instance().SetType(DEBUG).Put(val);
}
} Debug{};
static constexpr struct Log_Warning
{
template<class T>
Log& operator<<(const T& val) const
{
return Instance().SetType(WARNING).Put(val);
}
} Warning{};
static constexpr struct Log_Error
{
template<class T>
Log& operator<<(const T& val) const
{
return Instance().SetType(ERR).Put(val);
}
} Error{};
static constexpr struct Log_Colored
{
template<class T>
Log& operator<<(const T& val) const
{
return Instance().SetType(COLORED).Put(val);
}
} Colored{};
static Log& Endl(Log& log);
static Log& Instance()
{
static Log _Instance;
return _Instance;
}
};