summaryrefslogtreecommitdiff
path: root/src/format.hpp
blob: dd210c0278e4bf52233c20975a2c9a1bf6205356 (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
#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;
	case TRACE:
		prefix = "[DEBUG] ";
		break;
	default:
		prefix = "";
		break;
	}

	if (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