-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathboxr_logger.h
More file actions
62 lines (50 loc) · 1.52 KB
/
boxr_logger.h
File metadata and controls
62 lines (50 loc) · 1.52 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
#pragma once
#include <string_view>
#include <mq/Plugin.h>
#include <fmt/format.h>
#define LOGGER BoxrLogger::getInstance()
#define BOXR_LOG_HEADER "\a-t[\atMQ2Boxr\ax] "
class BoxrLogger {
public:
BoxrLogger(BoxrLogger const&) = delete;
void operator=(BoxrLogger const&) = delete;
static BoxrLogger& getInstance() {
static BoxrLogger instance;
return instance;
}
void setDebugEnabled(bool debugEnabled) {
this->debugEnabled = debugEnabled;
}
bool isDebugEnabled() {
return debugEnabled;
}
void toggleDebugEnabled() {
debugEnabled = !debugEnabled;
}
template <typename... Args>
void error(fmt::format_string<Args...> fmt, Args&&... args) {
doLog(errorFormat, fmt, std::forward<Args>(args)...);
}
template <typename... Args>
void info(fmt::format_string<Args...> fmt, Args&&... args) {
doLog(infoFormat, fmt, std::forward<Args>(args)...);
}
template <typename... Args>
void debug(fmt::format_string<Args...> fmt, Args&&... args) {
if (!debugEnabled) {
return;
}
doLog(debugFormat, fmt, std::forward<Args>(args)...);
}
private:
BoxrLogger() = default;
bool debugEnabled = false;
const char* infoFormat = BOXR_LOG_HEADER "%s";
const char* debugFormat = BOXR_LOG_HEADER "\a-y[\ayDEBUG\a-y] \ao %s";
const char* errorFormat = BOXR_LOG_HEADER "\a-r[\arERROR\ax] \ao %s";
template<typename... Args>
void doLog(const char* logFormat, fmt::format_string<Args...> fmt, Args&&... args) {
auto message = fmt::vformat(fmt, fmt::make_format_args(args...));
WriteChatf(logFormat, message.c_str());
}
};