#include #include #include #include namespace Void::Logging { HistoryLogger::HistoryLogger(std::filesystem::path path, Options options) : Logger(options.mode, options.capacity, options.policy), m_file( std::move(path), Detail::RollingFileOptions{options.max_bytes, options.max_files}), m_formatter(std::make_shared()) { if (!m_file.open()) { throw std::runtime_error(std::format( "HistoryLogger: cannot open '{}'", m_file.path().string())); } // History captures everything regardless of the global facade / // per-module filters; its own minimum level stays Trace. set_level(Level::Trace); Void::Log::debug("Log.History", "history log at '{}'", m_file.path().string()); } Void::Result::Result, Void::Result::Error> HistoryLogger::open(std::filesystem::path path, Options options) { try { return Void::Result::ok( std::make_unique(std::move(path), options)); } catch (const std::exception& e) { return Void::Result::fail(std::string{e.what()}); } } HistoryLogger::~HistoryLogger() noexcept { flush(); } void HistoryLogger::write(const Entry& entry) { m_file.write(m_formatter->format(entry)); m_file.flush(); } void HistoryLogger::on_flush(std::span entries) { for (const auto& e : entries) { m_file.write(m_formatter->format(e)); } m_file.flush(); } } // namespace Void::Logging