Files
Library/include/Void/Logging/FileLogger.hpp
T
faumarayandClaude Sonnet 4.6 a09e000f0f Add Hash, Random, Uuid, Encoding, Bits, Math modules + make Testing deps optional
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>
2026-05-14 21:52:22 +03:00

63 lines
1.8 KiB
C++

#pragma once
#include <Void/Logging/Logger.hpp>
#include <Void/Result/Error.hpp>
#include <Void/Result/Result.hpp>
#include <filesystem>
#include <fstream>
#include <memory>
#include <span>
namespace Void::Logging
{
/// Logger sink that appends formatted entries to a file on disk.
///
/// Defaults to Mode::Buffered with capacity 64 — entries are batched
/// via on_flush() and written using std::ofstream::flush() at the end
/// of every batch. The destructor flushes any remaining entries.
///
/// Two construction paths:
/// - `FileLogger::open(path)` returns
/// `Result<unique_ptr<FileLogger>, Error>` and never throws —
/// prefer this in code that already uses Void::Result for error
/// plumbing.
/// - The throwing constructor stays for callers that prefer
/// exceptions; it throws std::runtime_error if the path cannot
/// be opened for append.
class FileLogger final : public Logger
{
public:
explicit FileLogger(const std::filesystem::path& path,
Mode mode = Mode::Buffered,
std::size_t capacity = 64);
~FileLogger() noexcept override;
FileLogger(const FileLogger&) = delete;
FileLogger& operator=(const FileLogger&) = delete;
FileLogger(FileLogger&&) = delete;
FileLogger& operator=(FileLogger&&) = delete;
/// Non-throwing factory. On failure returns
/// `Failure<Error>{Error{"FileLogger: cannot open '<path>'"}}`.
[[nodiscard]] static Void::Result::
Result<std::unique_ptr<FileLogger>, Void::Result::Error>
open(const std::filesystem::path& path,
Mode mode = Mode::Buffered,
std::size_t capacity = 64);
protected:
void write(const Entry& entry) override;
void on_flush(std::span<const Entry> entries) override;
private:
std::filesystem::path m_path;
std::ofstream m_file;
};
} // namespace Void::Logging