Better defaults management, logger class implementation with logging levels, and write to file configuration implementation
This commit is contained in:
46
include/Logger.hpp
Normal file
46
include/Logger.hpp
Normal file
@@ -0,0 +1,46 @@
|
||||
// Logger.hpp
|
||||
#pragma once
|
||||
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
#include <ctime>
|
||||
#include <string>
|
||||
#include <filesystem>
|
||||
#include <stdexcept>
|
||||
#include <cstdlib>
|
||||
|
||||
#include "LoggingLevels.hpp"
|
||||
#include "DPMDefaults.hpp"
|
||||
|
||||
class Logger {
|
||||
public:
|
||||
// constructor
|
||||
Logger();
|
||||
|
||||
// destructor
|
||||
~Logger();
|
||||
|
||||
// Log method that accepts a string
|
||||
void log(LoggingLevels log_level, const std::string& message);
|
||||
|
||||
// Configuration setters
|
||||
void setLogFile(const std::string& log_file);
|
||||
void setWriteToLog(bool write_to_log);
|
||||
void setLogLevel(LoggingLevels log_level);
|
||||
|
||||
// String to LoggingLevels conversion
|
||||
static LoggingLevels stringToLogLevel(const std::string& level_str, LoggingLevels default_level = LoggingLevels::INFO);
|
||||
|
||||
private:
|
||||
// the logging level to stay initialized to
|
||||
LoggingLevels log_level;
|
||||
|
||||
// whether or not to log to file
|
||||
bool log_to_file;
|
||||
|
||||
// log file path
|
||||
std::string log_file;
|
||||
};
|
||||
|
||||
// Global logger instance
|
||||
extern Logger g_logger;
|
||||
Reference in New Issue
Block a user