Reflection and filesystem

Signed-off-by: faumaray <faumaray@gmail.com>
This commit is contained in:
faumaray committed 2026-05-03 18:09:46 +03:00
1 parent f0825fbd1a
commit 42268c6c35
45 files changed
+2732 -262

No files matched your search

+50
View File
@@ -0,0 +1,50 @@
#include <Void/Logging/FileLogger.hpp>
#include <format>
#include <stdexcept>
namespace Void::Logging
{
FileLogger::FileLogger(const std::filesystem::path& path,
Mode mode,
std::size_t capacity)
: Logger(mode, capacity), m_file(path, std::ios::app)
{
if (!m_file.is_open()) {
throw std::runtime_error(
std::format("FileLogger: cannot open '{}'", path.string()));
}
}
Void::Result::Result<std::unique_ptr<FileLogger>, Void::Result::Error>
FileLogger::open(const std::filesystem::path& path,
Mode mode,
std::size_t capacity)
{
try {
return Void::Result::ok(
std::make_unique<FileLogger>(path, mode, capacity));
} catch (const std::exception& e) {
return Void::Result::fail(std::string{e.what()});
}
}
FileLogger::~FileLogger() noexcept { flush(); }
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<const Entry> entries)
{
for (const auto& e : entries) {
m_file << std::format("[{}] {}\n", to_string(e.level), e.message);
}
m_file.flush();
}
} // namespace Void::Logging