-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlog.cpp
More file actions
94 lines (87 loc) · 2.24 KB
/
log.cpp
File metadata and controls
94 lines (87 loc) · 2.24 KB
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
#include <logger/log.h>
void logger::success(const std::string message, bool newline) noexcept(true) {
if (ENABLED) {
std::cout << getTime();
if (BEAUTIFY)
std::cout << GREEN;
std::cout << "[SUCCESS]";
if (BEAUTIFY)
std::cout << RESET;
std::cout << ": " << message;
if (newline)
std::cout << "\n";
}
std::cout.flush();
}
void logger::info(const std::string message, bool newline) noexcept(true) {
if (ENABLED) {
std::cout << getTime();
if (BEAUTIFY)
std::cout << BLUE;
std::cout << "[INFO] ";
if (BEAUTIFY)
std::cout << RESET;
std::cout << ": " << message;
if (newline)
std::cout << "\n";
}
std::cout.flush();
}
void logger::debug(const std::string message, bool newline) noexcept(true) {
if (ENABLED) {
std::cout << getTime();
if (BEAUTIFY)
std::cout << MAGENTA;
std::cout << "[DEBUG] ";
if (BEAUTIFY)
std::cout << RESET;
std::cout << ": " << message;
if (newline)
std::cout << "\n";
}
std::cout.flush();
}
void logger::warning(const std::string message, bool newline) noexcept(true) {
if (ENABLED) {
std::cout << getTime();
if (BEAUTIFY)
std::cout << YELLOW;
std::cout << "[WARNING]";
if (BEAUTIFY)
std::cout << RESET;
std::cout << ": " << message;
if (newline)
std::cout << "\n";
}
std::cout.flush();
}
void logger::error(const std::string message,
const std::string runtimeErrorMessage,
bool newline) noexcept(false) {
if (ENABLED) {
std::cerr << getTime();
if (BEAUTIFY)
std::cerr << RED;
std::cerr << "[ERROR] ";
if (BEAUTIFY)
std::cerr << RESET;
std::cerr << ": " << message;
if (newline)
std::cerr << "\n";
}
if (runtimeErrorMessage != "") {
throw std::runtime_error(runtimeErrorMessage);
}
std::cout.flush();
}
std::string logger::getTime() noexcept(true) {
if (!SHOW_TIME)
return "";
time_t currentTime =
std::chrono::system_clock::to_time_t(std::chrono::system_clock::now());
char timeStr[100];
std::strftime(timeStr, sizeof(timeStr), TIME_FORMAT.c_str(),
std::localtime(¤tTime));
std::string output(timeStr);
return "[" + output + "]";
}