Void::Log facade (header-only, macro-free):
- Leveled function templates trace/debug/info/warn/error/fatal(module,
fmt, args...) with lazy formatting - a disabled call is one relaxed
atomic load, no allocation, no formatting.
- Global min level + per-module overrides (can raise or lower); empty
sink/Disabled level = logging fully off; set_sink remains the splice
point for external logging libraries.
Void::Logging::Logger - async by default, one class for both modes:
- Mode::Async (default): lock-free MPSC queue + logger-owned worker
delivering batches via on_flush outside any lock; Immediate/Buffered
give synchronous behavior via constructor arg or set_mode at runtime.
- Bounded queue with OverflowPolicy{Block, DropNewest, DropOldest};
flush() (now virtual) blocks until everything submitted is delivered;
base destructor only stops/joins the worker, never touches virtuals.
- Fixed a wakeup race: stale park token + fresh release overflowed the
binary semaphore; wakeup is a counting semaphore (spurious wakes are
absorbed by the worker loop).
New sinks and formatters:
- RotatingFileLogger (size-based rotation, max-files cap), NullLogger,
CallbackLogger, MultiLogger (tee via new Logger::relay), SyslogLogger.
- Formatter interface: PatternFormatter ({time}/{level}/{scopes}/...),
JsonLinesFormatter, LogfmtFormatter; installable on Console/File/
Rotating sinks. Console/File sinks now default to Async.
- Logging::from_config builds the whole sink tree from Config keys;
apply_facade_config drives facade levels.
Configuration:
- Typed get_as<T>/get_or_as<T> (numbers, bool spellings, enums by name,
chrono durations), dotted keys, subtree(), sorted keys().
- New sources: from_env_prefix (APP_LOG__LEVEL -> log.level), from_ini
(sections as prefixes), from_json (objects/arrays flattened),
from_args (--key=value / --key value / --flag).
- Bind.hpp: reflection bind<T>(cfg, prefix) fills aggregates; defaults
in the struct are the schema; nested aggregates, optional, vector.
- Watch.hpp: ConfigWatch reloads on change with per-key diff; parse
failures keep the previous config.
System: new FileSystem::FileWatcher - debounced polling watcher (stable
mtime+size across N polls), callbacks off-thread, deletion events;
shared groundwork for plugin hot-reload.
Sweep: all internal Void::Log::log call sites migrated to the leveled
API ("Umbrella.Feature" labels); Plugin loader now logs load/reload.
918 tests green (28 new), stable across 30 consecutive runs, ASan+UBSan
clean.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
173 lines
5.9 KiB
C++
173 lines
5.9 KiB
C++
// Cross-module integration tests for the kitchen-sink VoidInternalTests
|
|
// binary. Exercises Logging + Result + Stacktrace + FileSystem + Log working
|
|
// together — the kind of thing the standalone per-module tests can't
|
|
// reach because they only link one module.
|
|
|
|
#include <Void/System/Path.hpp>
|
|
#include <Void/System/TempDir.hpp>
|
|
#include <Void/Log/Log.hpp>
|
|
#include <Void/Log/LoggingAdapter.hpp>
|
|
#include <Void/Log/ConsoleLogger.hpp>
|
|
#include <Void/Log/FileLogger.hpp>
|
|
#include <Void/Log/Level.hpp>
|
|
#include <Void/Functional/Error.hpp>
|
|
#include <Void/Functional/Result.hpp>
|
|
#include <Void/Stacktrace/Stacktrace.hpp>
|
|
#include <Void/Testing/Assert.hpp>
|
|
#include <Void/Testing/Test.hpp>
|
|
|
|
#include <filesystem>
|
|
#include <sstream>
|
|
#include <string>
|
|
|
|
namespace
|
|
{
|
|
struct ConfigError {
|
|
std::string file;
|
|
int line;
|
|
std::string detail;
|
|
};
|
|
} // namespace
|
|
|
|
// Reflection-based repr (Phase 2.6) renders user-defined error structs
|
|
// inside Testing assertions without any per-type formatter.
|
|
Void::Testing::Test repr_handles_user_error_struct()
|
|
{
|
|
const auto out = Void::Testing::Detail::repr(
|
|
ConfigError{"settings.toml", 17, "missing key 'name'"});
|
|
Void::Testing::expect(out.find("ConfigError") != std::string::npos);
|
|
Void::Testing::expect(out.find("file: settings.toml") != std::string::npos);
|
|
Void::Testing::expect(out.find("line: 17") != std::string::npos);
|
|
Void::Testing::expect(out.find("detail: missing key 'name'") !=
|
|
std::string::npos);
|
|
}
|
|
|
|
// Result + Stacktrace: read_source_snippet returns Result, and a missing
|
|
// file produces an Error whose chained message is rendered correctly.
|
|
Void::Testing::Test stacktrace_snippet_returns_result_on_missing_file()
|
|
{
|
|
auto r = Void::Stacktrace::read_source_snippet(
|
|
"/this/path/does/not/exist.cpp", 10);
|
|
Void::Testing::expect(!r.has_value());
|
|
const auto chained = Void::Result::with_context(r, "loading test fixture");
|
|
const auto rendered = chained.error().format();
|
|
Void::Testing::expect(rendered.find("loading test fixture") !=
|
|
std::string::npos);
|
|
Void::Testing::expect(rendered.find("read_source_snippet") !=
|
|
std::string::npos);
|
|
Void::Testing::expect(rendered.find("caused by:") != std::string::npos);
|
|
}
|
|
|
|
// Logging + Result: FileLogger::open returns Result; chained context
|
|
// surfaces meaningfully.
|
|
Void::Testing::Test file_logger_open_failure_chains_into_context()
|
|
{
|
|
auto r = Void::Logging::FileLogger::open("/no/such/dir/test.log");
|
|
Void::Testing::expect(!r.has_value());
|
|
auto wrapped =
|
|
Void::Result::with_context(std::move(r), "starting test runner");
|
|
const auto rendered = wrapped.error().format();
|
|
Void::Testing::expect(rendered.find("starting test runner") !=
|
|
std::string::npos);
|
|
Void::Testing::expect(rendered.find("FileLogger") != std::string::npos);
|
|
}
|
|
|
|
// Logging emits scope boundaries that survive into the output stream.
|
|
Void::Testing::Test logger_scope_entries_render_through_console_sink()
|
|
{
|
|
std::ostringstream out;
|
|
{
|
|
Void::Logging::ConsoleLogger log(out);
|
|
log.set_level(Void::Logging::Level::Trace);
|
|
auto scope = log.push_scope("worker");
|
|
log.info("doing work");
|
|
}
|
|
const auto content = out.str();
|
|
Void::Testing::expect(content.find("doing work") != std::string::npos);
|
|
Void::Testing::expect(content.find("worker") != std::string::npos);
|
|
}
|
|
|
|
// Logging + Result + FileSystem: roundtrip a chained error into a
|
|
// FileLogger sink and read it back through Void::FileSystem::read_file
|
|
// (no manual std::filesystem boilerplate, no manual cleanup).
|
|
Void::Testing::Test error_chain_logged_to_file_roundtrip()
|
|
{
|
|
Void::FileSystem::TempDir tmp;
|
|
const auto path = tmp / "log.txt";
|
|
|
|
{
|
|
auto sink_r = Void::Logging::FileLogger::open(
|
|
path, Void::Logging::Mode::Buffered, 8);
|
|
Void::Testing::expect(sink_r.has_value());
|
|
auto& sink = **sink_r;
|
|
|
|
Void::Result::Error inner{"socket closed"};
|
|
auto outer = inner.with_context("api request /users");
|
|
sink.error(outer.format());
|
|
}
|
|
|
|
auto read_back = Void::FileSystem::read_file(path);
|
|
Void::Testing::expect(read_back.has_value());
|
|
const auto& content = *read_back;
|
|
|
|
Void::Testing::expect(content.find("api request /users") !=
|
|
std::string::npos);
|
|
Void::Testing::expect(content.find("socket closed") != std::string::npos);
|
|
Void::Testing::expect(content.find("caused by:") != std::string::npos);
|
|
}
|
|
|
|
// Void::Log + Void::Logging: make_sink() bridges the two modules so that
|
|
// internal library events routed through Void::Log::log() surface in a
|
|
// Void::Logging::ConsoleLogger captured via a stringstream.
|
|
Void::Testing::Test log_adapter_routes_to_void_logging()
|
|
{
|
|
std::ostringstream out;
|
|
Void::Logging::ConsoleLogger logger{out};
|
|
logger.set_level(Void::Logging::Level::Trace);
|
|
|
|
Void::Log::set_sink(Void::Log::make_sink(logger));
|
|
|
|
Void::Log::log(
|
|
Void::Log::Level::Info, "TestModule", "hello from Void::Log");
|
|
Void::Log::log(Void::Log::Level::Warning, "TestModule", "a warning");
|
|
|
|
Void::Log::set_sink({});
|
|
logger.flush(); // ConsoleLogger is async by default
|
|
|
|
const auto text = out.str();
|
|
Void::Testing::expect(text.find("hello from Void::Log") !=
|
|
std::string::npos);
|
|
Void::Testing::expect(text.find("a warning") != std::string::npos);
|
|
Void::Testing::expect(text.find("[TestModule]") != std::string::npos);
|
|
}
|
|
|
|
// FileSystem operations now emit Void::Log events; verify they reach a sink.
|
|
Void::Testing::Test filesystem_ops_emit_log_events()
|
|
{
|
|
int debug_count = 0;
|
|
int warning_count = 0;
|
|
Void::Log::set_sink(
|
|
[&](Void::Log::Level l, std::string_view, std::string_view) {
|
|
if (l == Void::Log::Level::Debug) {
|
|
++debug_count;
|
|
}
|
|
if (l == Void::Log::Level::Warning) {
|
|
++warning_count;
|
|
}
|
|
});
|
|
|
|
Void::FileSystem::TempDir tmp;
|
|
auto p = tmp / "test.txt";
|
|
(void)Void::FileSystem::write_file(p, "data");
|
|
(void)Void::FileSystem::read_file(p);
|
|
(void)Void::FileSystem::read_file(tmp / "nonexistent.txt");
|
|
|
|
Void::Log::set_sink({});
|
|
|
|
// TempDir creation + read success + write (no debug from write_file) = at
|
|
// least 2
|
|
Void::Testing::expect(debug_count >= 2);
|
|
// Missing file read = 1 warning
|
|
Void::Testing::expect(warning_count >= 1);
|
|
}
|