This repository has been archived by the owner on Feb 3, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlogger.hpp
92 lines (76 loc) · 2.34 KB
/
logger.hpp
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
#pragma once
/**
* Copyright (C) 2020 Tristan. All Rights Reserved.
* This file is licensed under the BSD 2-Clause license.
* See the COPYING file for licensing information.
*/
#include <iostream>
#include <cstdlib>
namespace Logger {
/**
* These logging functions are used like this:
* <logtype>(<source>, <message>)
*
* e.g.:
* Error("NetworkStack::Start", "Couldn't connect to https://example.org");
*/
extern bool shouldLog;
void
RunAbort();
void
SetOutputState(bool) noexcept;
void
SetAbortFunction(void (*)()) noexcept;
template<typename SourceType, typename MessageType>
void
Error(const SourceType &source, const MessageType &message) noexcept {
if (shouldLog) {
std::cerr << "\033[1;31m[" << source << "] [ERROR] " << message << "\033[1;0m" << std::endl;
}
}
template<typename SourceType, typename MessageType>
void
Debug(const SourceType &source, const MessageType &message) noexcept {
if (shouldLog) {
std::cout << "\033[1;35m[" << source << "] [DEBUG] " << message << "\033[1;0m" << std::endl;
}
}
template<typename SourceType, typename MessageType>
void
Info(const SourceType &source, const MessageType &message) noexcept {
if (shouldLog) {
std::cout << '[' << source << "] [INFO] " << message << std::endl;
}
}
template<typename SourceType, typename MessageType>
void
Severe(const SourceType &source, const MessageType &message) noexcept {
if (shouldLog) {
std::cerr << "\033[1;91m[" << source << "] [SEVERE] " << message << "\033[1;0m" << std::endl;
}
}
#ifndef Success
template<typename SourceType, typename MessageType>
void
Success(const SourceType &source, const MessageType &message) noexcept {
if (shouldLog) {
std::cout << "\033[1;32m[" << source << "] [SUCCESS] " << message << "\033[1;0m" << std::endl;
}
}
#endif /* Success */
template<typename SourceType, typename MessageType>
void
Warning(const SourceType &source, const MessageType &message) noexcept {
if (shouldLog) {
std::cout << "\033[1;33m[" << source << "] [WARNING] " << message << "\033[1;0m" << std::endl;
}
}
template<typename SourceType, typename MessageType>
void
Crash(const SourceType &source, const MessageType &message) noexcept {
if (shouldLog) {
std::cout << "\033[1;33m[" << source << "] [CRASH] " << message << "\033[1;0m" << std::endl;
}
RunAbort();
}
} // namespace Logger