#ifndef LOGGER_H #define LOGGER_H #include #include #include #include #include #include #include #include #include #include #include enum class DiagnosticLevel { DEBUG, INFO, WARNING, ERROR, CRITICAL, NONE }; struct Record { std::string message; std::string context; std::chrono::time_point timestamp; DiagnosticLevel level; }; Record makeRecord(const std::string& message, const std::string& context, DiagnosticLevel level); std::string timestepToString(const std::chrono::time_point& timestamp); class Logger { private: static std::unordered_map instances; static std::mutex mapMutex; std::queue logQueue; std::mutex queueMutex; std::condition_variable queueCondition; std::thread logThread; std::atomic running; std::string filename; std::ofstream logFile; Logger(const std::string& filename); Logger(const Logger&) = delete; Logger& operator=(const Logger&) = delete; void processesLogs(); std::string levelAsString(DiagnosticLevel level); public: static Logger& getInstance(const std::string& filename); void log(const Record& record); void log(const std::string& message, const std::string& context, DiagnosticLevel level); void log(const std::string& message, DiagnosticLevel level); void log(const std::string& message); ~Logger(); }; #endif