Brunot
Loading...
Searching...
No Matches
Logging.h
Go to the documentation of this file.
1// File: Logging.h
2// Description:
3// .h file for Logging class that does the basic logging functionality
4// contains all the methods and variables needed for logging
5// Author(s): Marcelo Escamilla (marcelo.escamilla@digipen.edu)
6// 2025 / 09 / 14
7// (C) Digipen 2025
8// ____ __ __ __
9// /\__ _\/\ \ /\ \/\ \
10// \/_/\ \/\ \ \___ __ \ \ \_\ \ ___ __ __ ____ __
11// \ \ \ \ \ _ `\ /'__`\ \ \ _ \ / __`\/\ \/\ \ /',__\ /'__`\
12// \ \ \ \ \ \ \ \/\ __/ \ \ \ \ \/\ \L\ \ \ \_\ \/\__, `\/\ __/
13// \ \_\ \ \_\ \_\ \____\ \ \_\ \_\ \____/\ \____/\/\____/\ \____\
14// \/_/ \/_/\/_/\/____/ \/_/\/_/\/___/ \/___/ \/___/ \/____/
15#pragma once
16
17#include <spdlog/spdlog.h>
18#include <nlohmann/json.hpp>
19
20namespace sol
21{
22class state;
23}
24
26{
27
28public:
29 // Initialize the logging system ONE TIME USE in the AllocConsole section of wWinMain
30 // Add anything that is needed for logging to work any extra files, etc.
31 static auto initializeLogging() -> void;
32
33 // Methods
34
35 // Test output to console
36 static auto testOutput() -> void;
37
38 static auto bindLuaTypes(sol::state& lua) -> void;
39
40private:
41 // Variables
42 // static variable to keep track of log number
44
45};
46
47namespace hlg
48{
49
50// LogMessage: Verbose information
51// Send a message to the console with very detailed information you want others to know
52template <typename... Args>
53auto Trace(spdlog::format_string_t<Args...> message, Args&&... args) -> void
54{
55 spdlog::trace(message, std::forward<Args>(args)...);
56}
57
58// LogMessage: Verbose information
59// Send a message to the console with very detailed information you want others to know
60template <typename T>
61auto Trace(const T& message) -> void
62{
63 spdlog::trace(message);
64}
65
66// LogMessage: Debugging information
67// Send a message to the console with any debug information you want others to know
68template <typename... Args>
69auto Debug(spdlog::format_string_t<Args...> message, Args&&... args) -> void
70{
71 spdlog::debug(message, std::forward<Args>(args)...);
72}
73
74// LogMessage: Debugging information
75// Send a message to the console with any debug information you want others to know
76template <typename T>
77auto Debug(const T& message) -> void
78{
79 spdlog::debug(message);
80}
81
82// LogMessage: General information
83// Send a message to the console with any information you want others to know
84template <typename... Args>
85auto Message(spdlog::format_string_t<Args...> message, Args&&... args) -> void
86{
87 spdlog::info(message, std::forward<Args>(args)...);
88}
89
90// LogMessage: General information
91// Send a message to the console with any information you want others to know
92template <typename T>
93auto Message(const T& message) -> void
94{
95 spdlog::info(message);
96}
97
98// LogWarning: Warning information
99// Send a message to the console with any warning information you want others to know
100template <typename... Args>
101auto Warning(spdlog::format_string_t<Args...> message, Args&&... args) -> void
102{
103 spdlog::warn(message, std::forward<Args>(args)...);
104}
105
106// LogWarning: Warning information
107// Send a message to the console with any warning information you want others to know
108template <typename T>
109auto Warning(const T& message) -> void
110{
111 spdlog::warn(message);
112}
113
114// LogError: Error information
115// Send a message to the console with any error information you want others to know
116template <typename... Args>
117auto Error(spdlog::format_string_t<Args...> message, Args&&... args) -> void
118{
119 spdlog::error(message, std::forward<Args>(args)...);
120}
121
122// LogError: Error information
123// Send a message to the console with any error information you want others to know
124template <typename T>
125auto Error(const T& message) -> void
126{
127 spdlog::error(message);
128}
129
130// LogCritical: Critical information
131// Send a message to the console with any critical information you want others to know
132template <typename... Args>
133auto Critical(spdlog::format_string_t<Args...> message, Args&&... args) -> void
134{
135 spdlog::critical(message, std::forward<Args>(args)...);
136}
137
138// LogCritical: Critical information
139// Send a message to the console with any critical information you want others to know
140template <typename T>
141auto Critical(const T& message) -> void
142{
143 spdlog::critical(message);
144}
145
146} // namespace log
147
148// formatter for nlohmann::json to use with spdlog
149template <>
150struct fmt::formatter<nlohmann::json> : formatter<std::string>
151{
152 template <typename FormatContext>
153 auto format(const nlohmann::json& j, FormatContext& ctx) const
154 {
155 return formatter<std::string>::format(j.dump(), ctx);
156 }
157};
nlohmann::json json
Definition Json.cpp:19
Definition Logging.h:26
static auto bindLuaTypes(sol::state &lua) -> void
Definition Logging.cpp:99
int logNumber
Definition Logging.h:43
static auto testOutput() -> void
Definition Logging.cpp:89
static auto initializeLogging() -> void
Definition Logging.cpp:31
Definition Logging.h:48
auto Message(spdlog::format_string_t< Args... > message, Args &&... args) -> void
Definition Logging.h:85
auto Error(spdlog::format_string_t< Args... > message, Args &&... args) -> void
Definition Logging.h:117
auto Debug(spdlog::format_string_t< Args... > message, Args &&... args) -> void
Definition Logging.h:69
auto Critical(spdlog::format_string_t< Args... > message, Args &&... args) -> void
Definition Logging.h:133
auto Warning(spdlog::format_string_t< Args... > message, Args &&... args) -> void
Definition Logging.h:101
auto Trace(spdlog::format_string_t< Args... > message, Args &&... args) -> void
Definition Logging.h:53
Definition Script.h:230
Definition GameObject.h:27
auto format(const nlohmann::json &j, FormatContext &ctx) const
Definition Logging.h:153