49 lines
868 B
C++
49 lines
868 B
C++
#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_
|