2021-04-04 21:04:12 +01:00
|
|
|
#pragma once
|
|
|
|
|
|
2022-06-18 14:36:39 +01:00
|
|
|
#include <cstdint>
|
2021-04-04 21:04:12 +01:00
|
|
|
#include <string>
|
|
|
|
|
#include <mutex>
|
|
|
|
|
|
2021-12-31 17:05:31 +00:00
|
|
|
#include "src/ProjectConfig.hpp"
|
2022-12-26 22:10:49 +00:00
|
|
|
#include "src/Services/DateTimeService.hpp"
|
2021-04-04 21:04:12 +01:00
|
|
|
|
2023-08-13 15:47:51 +01:00
|
|
|
enum class LogLevel: std::uint8_t
|
2021-04-04 21:04:12 +01:00
|
|
|
{
|
2023-08-13 15:47:51 +01:00
|
|
|
INFO,
|
|
|
|
|
WARNING,
|
|
|
|
|
ERROR,
|
|
|
|
|
DEBUG,
|
|
|
|
|
};
|
2022-06-18 14:36:39 +01:00
|
|
|
|
2023-08-13 15:47:51 +01:00
|
|
|
/**
|
|
|
|
|
* Super simple thread safe static Logger class for basic logging.
|
|
|
|
|
*/
|
|
|
|
|
class Logger
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
static void configure(const ProjectConfig& projectConfig);
|
2021-04-04 21:04:12 +01:00
|
|
|
|
2023-08-13 15:47:51 +01:00
|
|
|
static void silence();
|
2021-04-04 21:04:12 +01:00
|
|
|
|
2023-08-13 15:47:51 +01:00
|
|
|
static void info(const std::string& message) {
|
|
|
|
|
if (Logger::infoPrintingEnabled) {
|
2023-09-22 22:23:53 +01:00
|
|
|
Logger::log(message, LogLevel::INFO);
|
2021-04-04 21:04:12 +01:00
|
|
|
}
|
2023-08-13 15:47:51 +01:00
|
|
|
}
|
2021-04-04 21:04:12 +01:00
|
|
|
|
2023-08-13 15:47:51 +01:00
|
|
|
static void warning(const std::string& message) {
|
|
|
|
|
if (Logger::warningPrintingEnabled) {
|
2023-09-22 22:23:53 +01:00
|
|
|
Logger::log(message, LogLevel::WARNING);
|
2021-04-04 21:04:12 +01:00
|
|
|
}
|
2023-08-13 15:47:51 +01:00
|
|
|
}
|
2021-04-04 21:04:12 +01:00
|
|
|
|
2023-08-13 15:47:51 +01:00
|
|
|
static void error(const std::string& message) {
|
|
|
|
|
if (Logger::errorPrintingEnabled) {
|
2023-09-22 22:23:53 +01:00
|
|
|
Logger::log(message, LogLevel::ERROR);
|
2021-04-04 21:04:12 +01:00
|
|
|
}
|
2023-08-13 15:47:51 +01:00
|
|
|
}
|
2021-04-04 21:04:12 +01:00
|
|
|
|
2023-08-13 15:47:51 +01:00
|
|
|
static void debug(const std::string& message) {
|
|
|
|
|
if (Logger::debugPrintingEnabled) {
|
2023-09-22 22:23:53 +01:00
|
|
|
Logger::log(message, LogLevel::DEBUG);
|
2021-04-04 21:04:12 +01:00
|
|
|
}
|
2023-08-13 15:47:51 +01:00
|
|
|
}
|
2021-04-04 21:04:12 +01:00
|
|
|
|
2023-08-13 15:47:51 +01:00
|
|
|
private:
|
|
|
|
|
static inline bool errorPrintingEnabled = true;
|
|
|
|
|
static inline bool warningPrintingEnabled = true;
|
|
|
|
|
static inline bool infoPrintingEnabled = true;
|
|
|
|
|
static inline bool debugPrintingEnabled = false;
|
2021-10-06 21:12:31 +01:00
|
|
|
|
2023-08-13 15:47:51 +01:00
|
|
|
static inline std::mutex printMutex;
|
2021-10-06 21:12:31 +01:00
|
|
|
|
2023-09-22 22:23:53 +01:00
|
|
|
static void log(const std::string& message, LogLevel level);
|
|
|
|
|
static const std::string& threadName();
|
2023-08-13 15:47:51 +01:00
|
|
|
};
|