Files
accordion/common/LoggerService.hpp

48 lines
913 B
C++

#pragma once
#include <vector>
#include <string>
#include <fstream>
#include <source_location>
#include <format>
#include "config/ConfigService.hpp"
#include "config/LoggerConfig.hpp"
enum LogFlag {
Debug,
Info,
Warning,
Error,
Count
};
static constexpr const char* LogFlagStrings[] = {
"Debug",
"Info",
"Warning",
"Error"
};
class LoggerService {
public:
LoggerService(ConfigService* config, const std::string& loggerId);
~LoggerService();
template<typename... Args>
void log(std::string component, LogFlag flag, std::format_string<Args...> message, Args&&... args) {
write(component, flag, std::format(message, std::forward<Args>(args)...));
}
private:
std::ofstream outfile_;
std::vector<LogFlag> activeFlags_;
LoggerParams configuration_;
void write(std::string component, LogFlag flag, std::string message);
};