Add logger singleton

This commit is contained in:
2024-01-21 21:48:29 +01:00
parent fc2744d7fa
commit b83f057e49
6 changed files with 68 additions and 26 deletions

View File

@@ -9,14 +9,6 @@
class TempLangFrontend {
public:
enum class LogLevel {
DEBUG,
INFO,
WARNING,
ERROR,
};
TempLangFrontend(const std::string &source_file)
{
m_source_file = source_file;
@@ -32,20 +24,7 @@ public:
protected:
std::string m_source_file;
void log(LogLevel lvl, const std::string &message) const
{
switch (lvl) {
case LogLevel::ERROR:
std::cerr << "[ERR]" << message << std::endl;
break;
case LogLevel::WARNING:
std::cerr << "[WARN]" << message << std::endl;
break;
default:
std::cout << message << std::endl;
break;
}
}
};

View File

@@ -39,7 +39,7 @@ public:
bool check_command(bool print_status) const;
}
};
}

View File

@@ -0,0 +1,31 @@
#ifndef _LOGGER_HPP_
#define _LOGGER_HPP_
#include <string>
enum class LogLevel {
DEBUG,
INFO,
WARNING,
ERROR,
};
class Logger {
public:
Logger(Logger &other) = delete;
void operator=(const Logger &) = delete;
void log(LogLevel lvl, const std::string &message) const;
static Logger *get_logger();
protected:
/* Create a proteceted instructure, to prevent construction outside of this class */
Logger();
static Logger *logger_inst;
};
#endif /* _LOGGER_HPP_ */