feat: add logger class

This commit is contained in:
2025-10-13 17:30:05 +02:00
parent 74a0bfca41
commit 41c9b68eb9
8 changed files with 185 additions and 22 deletions

48
src/logger.h Normal file
View File

@@ -0,0 +1,48 @@
#ifndef LOGGER_H_
#define LOGGER_H_
#include <sstream>
#include <string>
#include <vector>
// Utility: Concatenate any types into a string
template <typename... Args>
std::string sstr(Args&&... args)
{
std::ostringstream stream;
stream << std::dec;
((stream << args), ...);
return stream.str();
}
// Log types
enum class LogType {
info = 0,
warn,
error
};
// Log entry structure
struct LogEntry {
LogType type{LogType::info};
std::string message{};
};
// Logger class
class Logger {
public:
static void info(const std::string& message);
static void warn(const std::string& message);
static void error(const std::string& message);
[[nodiscard]] static const std::vector<LogEntry>& messages()
{
return messages_;
}
static void clear() { messages_.clear(); }
private:
inline static std::vector<LogEntry> messages_{};
};
#endif // LOGGER_H_