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
21{
22
23public:
24 // Initialize the logging system ONE TIME USE in the AllocConsole section of wWinMain
25 // Add anything that is needed for logging to work any extra files, etc.
26 static auto initializeLogging() -> void;
27
28 // Methods
29
30 // Test output to console
31 static auto testOutput() -> void;
32
33private:
34 // Variables
35 // static variable to keep track of log number
37
38};
39
40namespace hlg
41{
42
43// LogMessage: Verbose information
44// Send a message to the console with very detailed information you want others to know
45template <typename... Args>
46auto Trace(spdlog::format_string_t<Args...> message, Args&&... args) -> void
47{
48 spdlog::trace(message, std::forward<Args>(args)...);
49}
50
51// LogMessage: Verbose information
52// Send a message to the console with very detailed information you want others to know
53template <typename T>
54auto Trace(const T& message) -> void
55{
56 spdlog::trace(message);
57}
58
59// LogMessage: Debugging information
60// Send a message to the console with any debug information you want others to know
61template <typename... Args>
62auto Debug(spdlog::format_string_t<Args...> message, Args&&... args) -> void
63{
64 spdlog::debug(message, std::forward<Args>(args)...);
65}
66
67// LogMessage: Debugging information
68// Send a message to the console with any debug information you want others to know
69template <typename T>
70auto Debug(const T& message) -> void
71{
72 spdlog::debug(message);
73}
74
75// LogMessage: General information
76// Send a message to the console with any information you want others to know
77template <typename... Args>
78auto Message(spdlog::format_string_t<Args...> message, Args&&... args) -> void
79{
80 spdlog::info(message, std::forward<Args>(args)...);
81}
82
83// LogMessage: General information
84// Send a message to the console with any information you want others to know
85template <typename T>
86auto Message(const T& message) -> void
87{
88 spdlog::info(message);
89}
90
91// LogWarning: Warning information
92// Send a message to the console with any warning information you want others to know
93template <typename... Args>
94auto Warning(spdlog::format_string_t<Args...> message, Args&&... args) -> void
95{
96 spdlog::warn(message, std::forward<Args>(args)...);
97}
98
99// LogWarning: Warning information
100// Send a message to the console with any warning information you want others to know
101template <typename T>
102auto Warning(const T& message) -> void
103{
104 spdlog::warn(message);
105}
106
107// LogError: Error information
108// Send a message to the console with any error information you want others to know
109template <typename... Args>
110auto Error(spdlog::format_string_t<Args...> message, Args&&... args) -> void
111{
112 spdlog::error(message, std::forward<Args>(args)...);
113}
114
115// LogError: Error information
116// Send a message to the console with any error information you want others to know
117template <typename T>
118auto Error(const T& message) -> void
119{
120 spdlog::error(message);
121}
122
123// LogCritical: Critical information
124// Send a message to the console with any critical information you want others to know
125template <typename... Args>
126auto Critical(spdlog::format_string_t<Args...> message, Args&&... args) -> void
127{
128 spdlog::critical(message, std::forward<Args>(args)...);
129}
130
131// LogCritical: Critical information
132// Send a message to the console with any critical information you want others to know
133template <typename T>
134auto Critical(const T& message) -> void
135{
136 spdlog::critical(message);
137}
138
139} // namespace log
140
141// formatter for nlohmann::json to use with spdlog
142template <>
143struct fmt::formatter<nlohmann::json> : formatter<std::string>
144{
145 template <typename FormatContext>
146 auto format(const nlohmann::json& j, FormatContext& ctx) const
147 {
148 return formatter<std::string>::format(j.dump(), ctx);
149 }
150};
nlohmann::json json
Definition Json.cpp:19
Definition Logging.h:21
int logNumber
Definition Logging.h:36
static auto testOutput() -> void
Definition Logging.cpp:84
static auto initializeLogging() -> void
Definition Logging.cpp:30
Definition Logging.h:41
auto Message(spdlog::format_string_t< Args... > message, Args &&... args) -> void
Definition Logging.h:78
auto Error(spdlog::format_string_t< Args... > message, Args &&... args) -> void
Definition Logging.h:110
auto Debug(spdlog::format_string_t< Args... > message, Args &&... args) -> void
Definition Logging.h:62
auto Critical(spdlog::format_string_t< Args... > message, Args &&... args) -> void
Definition Logging.h:126
auto Warning(spdlog::format_string_t< Args... > message, Args &&... args) -> void
Definition Logging.h:94
auto Trace(spdlog::format_string_t< Args... > message, Args &&... args) -> void
Definition Logging.h:46
auto format(const nlohmann::json &j, FormatContext &ctx) const
Definition Logging.h:146