OpenRGB/LogManager.h
k1-801 ca11939277 Add LogManager and add log messages for the detection process
Commit amended for code style and to remove unrelated changes by Adam Honse <calcprogrammer1@gmail.com>
2021-03-05 14:57:53 -06:00

49 lines
1.1 KiB
C++

#ifndef LOGMANAGER_H
#define LOGMANAGER_H
#include <fstream>
#include <mutex>
#include <vector>
#include "json.hpp"
using json = nlohmann::json;
enum
{
LL_CRITICAL,
LL_ERROR,
LL_WARNING,
LL_NOTICE,
LL_VERBOSE,
LL_DEBUG
};
class LogManager
{
private:
LogManager();
LogManager(const LogManager&) = delete;
LogManager(LogManager&&) = delete;
~LogManager();
std::mutex entry_mutex;
std::mutex section_mutex;
std::vector<std::string> sections;
std::vector<int> loglevels;
std::ofstream log_stream;
std::vector<std::string> temp_messages;
std::vector<int> temp_levels;
std::vector<int> temp_sections;
void _flush();
public:
static LogManager* get();
void configure(json config, const std::string& defaultDir);
void flush();
void append(int section, int level, const char* fmt, ...);
int registerSection(const char* name, int loglevel);
};
#define LogSection(name,level) LogManager::get()->registerSection(name, level)
#define LogAppend LogManager::get()->append
#endif // LOGMANAGER_H