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>
87 lines
2.5 KiB
C++
87 lines
2.5 KiB
C++
#include <Void/Configuration/Bind.hpp>
|
|
#include <Void/Configuration/Config.hpp>
|
|
#include <Void/Testing/Assert.hpp>
|
|
#include <Void/Testing/Test.hpp>
|
|
|
|
#include <chrono>
|
|
#include <optional>
|
|
#include <string>
|
|
#include <vector>
|
|
|
|
#ifdef VOID_HAS_CONFIG_REFLECTION
|
|
|
|
using Void::Configuration::Config;
|
|
|
|
namespace
|
|
{
|
|
enum class Sink { Console, File };
|
|
|
|
struct FileSettings {
|
|
std::string path = "default.log";
|
|
int max_files = 3;
|
|
};
|
|
|
|
struct LogSettings {
|
|
std::string level = "info";
|
|
bool async = true;
|
|
Sink sink = Sink::Console;
|
|
std::chrono::milliseconds flush_every{250};
|
|
FileSettings file;
|
|
std::optional<int> sample_rate;
|
|
std::vector<std::string> tags;
|
|
};
|
|
} // namespace
|
|
|
|
Void::Testing::Test bind_fills_present_keys_keeps_defaults()
|
|
{
|
|
Config cfg;
|
|
cfg.set("log.level", "debug");
|
|
cfg.set("log.file.path", "/var/log/app.log");
|
|
cfg.set("log.flush_every", "1s");
|
|
|
|
const auto s = Void::Configuration::bind<LogSettings>(cfg, "log");
|
|
Void::Testing::expect(s.has_value());
|
|
Void::Testing::expect_eq(s->level, std::string{"debug"});
|
|
Void::Testing::expect(s->async); // default kept
|
|
Void::Testing::expect_eq(s->file.path, std::string{"/var/log/app.log"});
|
|
Void::Testing::expect_eq(s->file.max_files, 3); // nested default kept
|
|
Void::Testing::expect(s->flush_every ==
|
|
std::chrono::milliseconds{1000});
|
|
}
|
|
|
|
Void::Testing::Test bind_enum_optional_vector()
|
|
{
|
|
Config cfg;
|
|
cfg.set("log.sink", "File");
|
|
cfg.set("log.sample_rate", "10");
|
|
cfg.set("log.tags.0", "alpha");
|
|
cfg.set("log.tags.1", "beta");
|
|
|
|
const auto s = Void::Configuration::bind<LogSettings>(cfg, "log");
|
|
Void::Testing::expect(s.has_value());
|
|
Void::Testing::expect(s->sink == Sink::File);
|
|
Void::Testing::expect(s->sample_rate.has_value());
|
|
Void::Testing::expect_eq(*s->sample_rate, 10);
|
|
Void::Testing::expect_eq(s->tags.size(), std::size_t{2});
|
|
Void::Testing::expect_eq(s->tags[1], std::string{"beta"});
|
|
}
|
|
|
|
Void::Testing::Test bind_reports_conversion_errors()
|
|
{
|
|
Config cfg;
|
|
cfg.set("log.async", "not-a-bool");
|
|
const auto s = Void::Configuration::bind<LogSettings>(cfg, "log");
|
|
Void::Testing::expect(!s.has_value());
|
|
}
|
|
|
|
Void::Testing::Test bind_empty_prefix_binds_root_keys()
|
|
{
|
|
Config cfg;
|
|
cfg.set("path", "root.log");
|
|
const auto s = Void::Configuration::bind<FileSettings>(cfg);
|
|
Void::Testing::expect(s.has_value());
|
|
Void::Testing::expect_eq(s->path, std::string{"root.log"});
|
|
}
|
|
|
|
#endif // VOID_HAS_CONFIG_REFLECTION
|