blob: f857f96901ca5bd1b4a4dd95e6bd31f7079a2b2c (
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
|
#pragma once
#include <format>
#include <string>
enum eFormatType : int8_t {
NONE,
TRACE,
LOG,
WARN,
ERR,
SYS,
NONEWLINE
};
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;
#ifdef DEBUG
case TRACE:
prefix = "[DEBUG] ";
break;
#endif
default:
prefix = "";
break;
}
if (!str.empty() && str.back() != '\n' && type != NONEWLINE)
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
|