summaryrefslogtreecommitdiff
path: root/src/format.hpp
blob: f079535915f53c670697bb6b62d733caa69a5b5b (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
#pragma once
#include <format>
#include <string>

enum eFormatType : int8_t {
	NONE,
	TRACE,
	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