#include #include #include #include namespace Void::Logging { FileLogger::FileLogger(const std::filesystem::path& path, Mode mode, std::size_t capacity) : Logger(mode, capacity), m_path(path), m_file(path, std::ios::app) { if (!m_file.is_open()) { Void::Log::log( Void::Log::Level::Warning, "Logging", std::format("FileLogger: cannot open '{}'", path.string())); throw std::runtime_error( std::format("FileLogger: cannot open '{}'", path.string())); } Void::Log::log(Void::Log::Level::Debug, "Logging", std::format("FileLogger: opened '{}'", path.string())); } Void::Result::Result, Void::Result::Error> FileLogger::open(const std::filesystem::path& path, Mode mode, std::size_t capacity) { try { return Void::Result::ok( std::make_unique(path, mode, capacity)); } catch (const std::exception& e) { return Void::Result::fail(std::string{e.what()}); } } FileLogger::~FileLogger() noexcept { flush(); Void::Log::log(Void::Log::Level::Debug, "Logging", std::format("FileLogger: closed '{}'", m_path.string())); } void FileLogger::write(const Entry& entry) { m_file << std::format( "[{}] {}\n", to_string(entry.level), entry.message); m_file.flush(); } void FileLogger::on_flush(std::span entries) { for (const auto& e : entries) { m_file << std::format("[{}] {}\n", to_string(e.level), e.message); } m_file.flush(); } } // namespace Void::Logging