Add logger singleton
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
};
|
||||
|
||||
|
@@ -39,7 +39,7 @@ public:
|
||||
|
||||
|
||||
bool check_command(bool print_status) const;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
}
|
||||
|
31
tprcc/include/tprcc/logger.hpp
Normal file
31
tprcc/include/tprcc/logger.hpp
Normal 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_ */
|
Reference in New Issue
Block a user