blob: 6dc5e4d116c210b85de8bc02f91263028eb39fc4 (
plain)
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
|
#pragma once
#include <format>
#include <string>
enum eFormatType : int8_t {
NONE,
LOG,
WARN,
ERR,
SYS,
CHAT,
};
namespace NFormatter {
inline std::string fmt(eFormatType type, std::string str) {
std::string prefix;
switch (type) {
case LOG: prefix = "[LOG] "; break;
case WARN: prefix = "[WARN] "; break;
case ERR: prefix = "[ERROR] "; break;
case SYS: prefix = "[SYSTEM] "; break;
case CHAT: prefix = "[CHAT] "; break;
default: prefix = ""; break;
}
if (!str.empty() && str.back() != '\n' && !prefix.empty())
str += '\n';
return prefix + str;
}
template <typename... Args>
std::string fmt(eFormatType type, std::format_string<Args...> fmt, Args &&...args) {
return NFormatter::fmt(type, std::format(fmt, std::forward<Args>(args)...));
}
} // namespace NFormatter
|