New header-only modules: - Void::Hash — FNV-1a 32/64, CRC-32, DJB2, MurmurHash3-32, UDL literals - Void::Random — Xoshiro256** PRNG, uniform_int/real, coin_flip, shuffle, random_string - Void::Uuid — v4 (random), v5_lite (name-based), parse, RFC 4122 namespaces - Void::Encoding — Base64 (standard + URL-safe), Hex encode/decode - Void::Bits — popcount, bit extract/deposit, rotation, align, byteswap, masks - Void::Math — Vec2/Vec3/Vec4, Mat4 (identity, translation, scale, rotation) Testing module: move Stacktrace from INTERNAL_DEPS to OPTIONAL_DEPS. Added Detail/Color.hpp shim that delegates to Stacktrace::Color when present or provides inline ANSI fallback otherwise. All Stacktrace calls in SignalHandler, ConsoleReporter, and Runner are gated on VOID_HAS_STACKTRACE. Fix Repr.hpp reflect_struct to handle template specializations that lack std::meta::identifier_of (now guarded by has_identifier check). 33/33 tests pass. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
63 lines
1.6 KiB
C++
63 lines
1.6 KiB
C++
#include <Void/Logging/FileLogger.hpp>
|
|
#include <Void/Log/Log.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_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<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::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<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
|