TheAtlasEngine
 
Loading...
Searching...
No Matches
engine_logger.hpp
1#pragma once
2#include <core/core.hpp>
3#include <fmt/os.h>
4#include <fmt/ostream.h>
5#include <memory>
6#include <spdlog/common.h>
7#include <spdlog/spdlog.h>
8
9namespace atlas {
17 public:
25 const std::string& pattern = "%^[%T] %n: %v%$");
26
30 static void set_current_logger(
31 const std::string& p_tag = "Undefined g_Tag in console_logger");
32
36 static void create_new_logger(
37 const std::string& p_tag = "Undefined Tag");
38
47 static ref<spdlog::logger> get(const std::string& p_tag);
48
49 private:
50 // Using an unordered_map to specify through a string what logger to
51 // retrieve to log messages
52 static std::unordered_map<std::string, ref<spdlog::logger>> s_loggers;
53 };
54};
55
60template<typename... T>
61inline void
62console_log_trace([[maybe_unused]] spdlog::format_string_t<T...> fmt,
63 [[maybe_unused]] T&&... args) {
64#ifndef ENABLE_TESTS_ONLY
66 ->trace(fmt, std::forward<T>(args)...);
67#endif
68}
69
70template<typename... T>
71inline void
72console_log_warn([[maybe_unused]] spdlog::format_string_t<T...> fmt,
73 [[maybe_unused]] T&&... args) {
74#ifndef ENABLE_TESTS_ONLY
76 ->warn(fmt, std::forward<T>(args)...);
77#endif
78}
79
80template<typename... T>
81inline void
82console_log_info([[maybe_unused]] spdlog::format_string_t<T...> fmt,
83 [[maybe_unused]] T&&... args) {
84#ifndef ENABLE_TESTS_ONLY
86 ->info(fmt, std::forward<T>(args)...);
87#endif
88}
89
90template<typename... T>
91inline void
92console_log_error([[maybe_unused]] spdlog::format_string_t<T...> fmt,
93 [[maybe_unused]] T&&... args) {
94#ifndef ENABLE_TESTS_ONLY
96 ->error(fmt, std::forward<T>(args)...);
97#endif
98}
99
100template<typename... T>
101inline void
102console_log_fatal([[maybe_unused]] spdlog::format_string_t<T...> fmt,
103 [[maybe_unused]] T&&... args) {
104#ifndef ENABLE_TESTS_ONLY
106 ->critical(fmt, std::forward<T>(args)...);
107#endif
108}
109
113template<typename... T>
114inline void
115console_log_trace_tagged([[maybe_unused]] const std::string& p_tag,
116 [[maybe_unused]] spdlog::format_string_t<T...> fmt,
117 [[maybe_unused]] T&&... args) {
118#ifndef ENABLE_TESTS_ONLY
119 atlas::console_log_manager::get(p_tag)->trace(fmt,
120 std::forward<T>(args)...);
121#endif
122}
123
124template<typename... T>
125inline void
126console_log_info_tagged([[maybe_unused]] const std::string& p_tag,
127 [[maybe_unused]] spdlog::format_string_t<T...> fmt,
128 [[maybe_unused]] T&&... args) {
129#ifndef ENABLE_TESTS_ONLY
130 atlas::console_log_manager::get(p_tag)->info(fmt, std::forward<T>(args)...);
131#endif
132}
133
134template<typename... T>
135inline void
136console_log_warn_tagged([[maybe_unused]] const std::string& p_tag,
137 [[maybe_unused]] spdlog::format_string_t<T...> fmt,
138 [[maybe_unused]] T&&... args) {
139 atlas::console_log_manager::get(p_tag)->warn(fmt, std::forward<T>(args)...);
140}
141
142template<typename... T>
143inline void
144console_log_error_tagged([[maybe_unused]] const std::string& p_tag,
145 [[maybe_unused]] spdlog::format_string_t<T...> fmt,
146 [[maybe_unused]] T&&... args) {
147#ifndef ENABLE_TESTS_ONLY
148 atlas::console_log_manager::get(p_tag)->error(fmt,
149 std::forward<T>(args)...);
150#endif
151}
152
153template<typename... T>
154inline void
155console_log_fatal_tagged([[maybe_unused]] const std::string& p_tag,
156 [[maybe_unused]] spdlog::format_string_t<T...> fmt,
157 [[maybe_unused]] T&&... args) {
158#ifndef ENABLE_TESTS_ONLY
159 atlas::console_log_manager::get(p_tag)->critical(fmt,
160 std::forward<T>(args)...);
161#endif
162}
logger for logging messages to stdout on the console
Definition engine_logger.hpp:16
static void create_new_logger(const std::string &p_tag="Undefined Tag")
constructs a new spdlog::logger to write to the console
static ref< spdlog::logger > get(const std::string &p_tag)
retrieves that specific logger if it has been constructed
static void initialize_logger_manager(const std::string &pattern="%^[%T] %n: %v%$")
initializes the console_log_manager
static void set_current_logger(const std::string &p_tag="Undefined g_Tag in console_logger")
sets what the current logger to write to the console with