Steppable 0.0.1
A CAS project written from scratch in C++
Loading...
Searching...
No Matches
logging.hpp
1/**************************************************************************************************
2 * Copyright (c) 2023-2025 NWSOFT *
3 * *
4 * Permission is hereby granted, free of charge, to any person obtaining a copy *
5 * of this software and associated documentation files (the "Software"), to deal *
6 * in the Software without restriction, including without limitation the rights *
7 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell *
8 * copies of the Software, and to permit persons to whom the Software is *
9 * furnished to do so, subject to the following conditions: *
10 * *
11 * The above copyright notice and this permission notice shall be included in all *
12 * copies or substantial portions of the Software. *
13 * *
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR *
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE *
17 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER *
18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, *
19 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE *
20 * SOFTWARE. *
21 **************************************************************************************************/
22
38
39#pragma once
40
41#include <fstream>
42#include <string>
43
51{
58 enum Level
59 {
61 ERR = 3,
65 INFO = 1,
67 DBG = 0
68 };
69
77 class Logger
78 {
79 public:
86#if DEBUG
87 Logger(const std::string& name, const std::string& filename, Level level = Level::DBG);
88#else
89 Logger(const std::string& name, const std::string& filename, const Level level = Level::INFO);
90#endif
91
95 ~Logger();
96
101 void error(const std::string& message);
102
108 template<typename... Args>
109 void error(const std::string& message, Args... args)
110 {
111 auto formattedMsg = vFormat(message, args...);
112 error(formattedMsg);
113 }
114
119 void warning(const std::string& message);
120
126 template<typename... Args>
127 void warning(const std::string& message, Args... args)
128 {
129 auto formattedMsg = vFormat(message, args...);
130 warning(formattedMsg);
131 }
132
137 void info(const std::string& message);
138
143 void debug(const std::string& message);
144
150 template<typename... Args>
151 void debug(const std::string& message, Args... args)
152 {
153 auto formattedMsg = vFormat(message, args...);
154 debug(formattedMsg);
155 }
156
157 private:
161 std::ofstream file;
162
165
167 std::string name;
168
174 void log(const std::string& message);
175 };
176} // namespace steppable::__internals::logging
std::ofstream file
The log file stream.
Definition logging.hpp:161
Logger(const std::string &name, const std::string &filename, const Level level=Level::INFO)
Constructs a Logger object.
Definition logging.cpp:36
Level level
The default logging level.
Definition logging.hpp:164
void log(const std::string &message)
Logs a message.
Definition logging.cpp:45
void warning(const std::string &message, Args... args)
Logs a warning message with additional arguments.
Definition logging.hpp:127
~Logger()
Destroys the Logger object.
Definition logging.cpp:43
std::string name
The name of the logger. This will be prepended to the log messages.
Definition logging.hpp:167
void error(const std::string &message, Args... args)
Logs an error message with additional arguments.
Definition logging.hpp:109
void debug(const std::string &message, Args... args)
Logs a debug message with additional arguments.
Definition logging.hpp:151
void warning(const std::string &message)
Logs a warning message.
Definition logging.cpp:60
void error(const std::string &message)
Logs an error message.
Definition logging.cpp:54
void debug(const std::string &message)
Logs a debug message.
Definition logging.cpp:72
void info(const std::string &message)
Logs an info message.
Definition logging.cpp:66
The logging namespace contains classes and functions for logging. The logging namespace contains the ...
Definition logging.cpp:32
Level
Enumeration of logging levels.
Definition logging.hpp:59
@ ERR
Logs ONLY error messages.
Definition logging.hpp:61
@ INFO
Logs error, warning, and info messages. Recommended for release.
Definition logging.hpp:65
@ DBG
Logs error, warning, info, and debug messages. Basically, logs everything.
Definition logging.hpp:67
@ WARNING
Logs error and warning messages.
Definition logging.hpp:63
Untitled