diff options
| author | littleblack111 <littleblack11111@gmail.com> | 2025-06-12 21:41:41 +0800 |
|---|---|---|
| committer | littleblack111 <littleblack11111@gmail.com> | 2025-06-13 20:22:51 +0800 |
| commit | 6f7b994684032060f0a2d7af82f4f3572293b8d6 (patch) | |
| tree | 793d328cbcd6761365267550b55db45aee9b21fc /src/debug/format.hpp | |
| parent | 6a51ab4525c59e9fe2bdbd92493019b0a98c6b94 (diff) | |
internal!: organized internal structure, using cmake now
Diffstat (limited to 'src/debug/format.hpp')
| -rw-r--r-- | src/debug/format.hpp | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/src/debug/format.hpp b/src/debug/format.hpp new file mode 100644 index 0000000..f857f96 --- /dev/null +++ b/src/debug/format.hpp @@ -0,0 +1,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 |
