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
16namespace galaxy
17{
21 enum class LogLevel : int
22 {
26 INFO = 0,
27
31 WARNING = 1,
32
36 ERROR = 2,
37
41 FATAL = 3
42 };
43
44 template<LogLevel level>
45 constexpr const char* const get_loglevel_colour()
46 {
47 if constexpr (level == LogLevel::INFO)
48 {
49 return "\x1b[1m\x1b[37m";
50 }
51 else if constexpr (level == LogLevel::WARNING)
52 {
53 return "\x1b[1m\x1b[33m";
54 }
55 else if constexpr (level == LogLevel::ERROR)
56 {
57 return "\x1b[1m\x1b[31m";
58 }
59 else if constexpr (level == LogLevel::FATAL)
60 {
61 return "\x1b[41m\x1b[37m";
62 }
63 }
64} // namespace galaxy
65
66template<>
67struct std::formatter<galaxy::LogLevel> : std::formatter<std::string>
68{
69 auto format(const galaxy::LogLevel& level, format_context& ctx) const
70 {
71 return std::formatter<std::string>::format(std::string {magic_enum::enum_name<galaxy::LogLevel>(level)}, ctx);
72 }
73};
74
75#endif
Timer.hpp galaxy.
Definition Timer.cpp:18
LogLevel
Used to determine filtering and colouring of log messages.
Definition LogLevel.hpp:22
@ 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:45
auto format(const galaxy::LogLevel &level, format_context &ctx) const
Definition LogLevel.hpp:69