galaxy 1.0.0
Real-Time C++23 Game Programming Framework. Built on data-driven design principles and agile software engineering.
Loading...
Searching...
No Matches
LogLevel.hpp
Go to the documentation of this file.
1
7
8#ifndef GALAXY_LOGGING_LOGLEVEL_HPP_
9#define GALAXY_LOGGING_LOGLEVEL_HPP_
10
11#include <format>
12#include <string>
13
14#include <magic_enum/magic_enum.hpp>
15
16#undef ERROR
17
18namespace galaxy
19{
23 enum class LogLevel : int
24 {
28 INFO = 0,
29
33 WARNING = 1,
34
38 ERROR = 2,
39
43 FATAL = 3
44 };
45
46 template<LogLevel level>
47 constexpr const char* const get_loglevel_colour()
48 {
49 if constexpr (level == LogLevel::INFO)
50 {
51 return "\x1b[1m\x1b[37m";
52 }
53 else if constexpr (level == LogLevel::WARNING)
54 {
55 return "\x1b[1m\x1b[33m";
56 }
57 else if constexpr (level == LogLevel::ERROR)
58 {
59 return "\x1b[1m\x1b[31m";
60 }
61 else if constexpr (level == LogLevel::FATAL)
62 {
63 return "\x1b[41m\x1b[37m";
64 }
65 }
66} // namespace galaxy
67
68template<>
69struct std::formatter<galaxy::LogLevel> : std::formatter<std::string>
70{
71 auto format(const galaxy::LogLevel& level, format_context& ctx) const noexcept
72 {
73 return std::formatter<std::string>::format(std::string {magic_enum::enum_name<galaxy::LogLevel>(level)}, ctx);
74 }
75};
76
77#endif
Application.hpp galaxy.
LogLevel
Used to determine filtering and colouring of log messages.
Definition LogLevel.hpp:24
@ WARNING
Warning Log Level.
@ FATAL
Fatal Log Level.
@ INFO
Info Log Level.
@ ERROR
Error Log Level.
constexpr const char *const get_loglevel_colour()
Definition LogLevel.hpp:47
auto format(const galaxy::LogLevel &level, format_context &ctx) const noexcept
Definition LogLevel.hpp:71