#pragma once #include "api.h" #include namespace api::log { //-------------------------------------------------------------- // Log levels //-------------------------------------------------------------- enum class LogLevel : uint8_t { Message = 0, Debug, Info, Warning, Error, System, // Reserved for system-level logs, not intended for user messages }; //-------------------------------------------------------------- /* --- */ //-------------------------------------------------------------- // Log message structure //-------------------------------------------------------------- struct LogMessage : dBus::api::DefaultData { using Timestamp = std::chrono::steady_clock::time_point; virtual ~LogMessage() = default; Timestamp timestamp = std::chrono::steady_clock::now(); LogLevel level = LogLevel::Message; std::string message; [[nodiscard]] std::string toString() const override { const auto timestampFormatter = Age(std::chrono::duration_cast(timestamp.time_since_epoch())); const auto logEntry = std::format("{}{}", getLevelString(), message); return logEntry; } private: [[nodiscard]] std::string getLevelString() const { switch (level) { using enum LogLevel; case Debug: return "[Debug] "; case Info: return "[Info] "; case Warning: return "[Warning] "; case Error: return "[Error] "; case System: return "[System] "; default: return ""; } } }; //-------------------------------------------------------------- } // namespace api::log