Log: carry call-site source_location through to the sink

Every log line showed LoggingAdapter.hpp as its source because make_sink
called Void::Logging::Logger::log() with a defaulted source_location captured
inside the adapter, discarding the real call site.

Capture std::source_location at each Void::Log::{info,warn,...} call via an
FmtLoc wrapper (the same trick Logger uses internally), thread it through a
4-argument Sink, and forward it from make_sink to logger.log(). Sinks now
receive the originating file/line/function.

Formatted emission is routed through a single non-overloaded Detail::emit():
forwarding a (level, module, std::string, source_location) call to the public
log() would otherwise also match the variadic log() overload, deducing
source_location as a format argument and failing in FmtLoc's consteval ctor.

Sink is now a 4-arg callable; updated the bundled tests accordingly.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
faumarayandClaude Opus 4.8 committed 2026-06-25 02:35:42 +03:00
1 parent e4ddb0c8c4
commit 2d3f9dc319
5 files changed
+97 -49

No files matched your search

+2 -1
View File
@@ -147,7 +147,8 @@ 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) {
[&](Void::Log::Level l, std::string_view, std::string_view,
const std::source_location&) {
if (l == Void::Log::Level::Debug) {
++debug_count;
}
+1 -1
View File
@@ -121,7 +121,7 @@ Void::Testing::Test apply_facade_config_sets_levels()
cfg.set("log.module_levels.Fsm", "trace");
Void::Logging::apply_facade_config(cfg);
Void::Log::set_sink([](auto, auto, auto) {});
Void::Log::set_sink([](auto, auto, auto, auto) {});
Void::Testing::expect(
!Void::Log::enabled(Void::Log::Level::Info, "Other"));
Void::Testing::expect(
+17 -15
View File
@@ -35,7 +35,8 @@ Void::Testing::Test sink_receives_all_fields()
std::string got_message;
Void::Log::set_sink(
[&](Void::Log::Level l, std::string_view mod, std::string_view msg) {
[&](Void::Log::Level l, std::string_view mod, std::string_view msg,
const std::source_location&) {
got_level = l;
got_module = mod;
got_message = msg;
@@ -54,10 +55,10 @@ Void::Testing::Test set_sink_replaces_previous()
int first_calls = 0;
int second_calls = 0;
Void::Log::set_sink([&](auto, auto, auto) { ++first_calls; });
Void::Log::set_sink([&](auto, auto, auto, auto) { ++first_calls; });
Void::Log::log(Void::Log::Level::Info, "m", "a");
Void::Log::set_sink([&](auto, auto, auto) { ++second_calls; });
Void::Log::set_sink([&](auto, auto, auto, auto) { ++second_calls; });
Void::Log::log(Void::Log::Level::Info, "m", "b");
Void::Testing::expect_eq(first_calls, 1);
@@ -68,7 +69,7 @@ Void::Testing::Test clear_sink_silences_output()
{
SinkGuard guard;
int calls = 0;
Void::Log::set_sink([&](auto, auto, auto) { ++calls; });
Void::Log::set_sink([&](auto, auto, auto, auto) { ++calls; });
Void::Log::log(Void::Log::Level::Info, "m", "before clear");
Void::Log::set_sink({});
Void::Log::log(Void::Log::Level::Info, "m", "after clear");
@@ -79,7 +80,7 @@ Void::Testing::Test concurrent_log_calls_are_safe()
{
SinkGuard guard;
std::atomic<int> count{0};
Void::Log::set_sink([&](auto, auto, auto) { ++count; });
Void::Log::set_sink([&](auto, auto, auto, auto) { ++count; });
constexpr int N = 64;
std::vector<std::thread> threads;
@@ -100,7 +101,7 @@ Void::Testing::Test all_levels_are_forwarded()
{
SinkGuard guard;
int calls = 0;
Void::Log::set_sink([&](auto, auto, auto) { ++calls; });
Void::Log::set_sink([&](auto, auto, auto, auto) { ++calls; });
Void::Log::log(Void::Log::Level::Trace, "m", "t");
Void::Log::log(Void::Log::Level::Debug, "m", "d");
@@ -119,10 +120,11 @@ Void::Testing::Test leveled_helpers_format_arguments()
SinkGuard guard;
std::string got;
Void::Log::Level got_level{};
Void::Log::set_sink([&](Void::Log::Level l, auto, std::string_view msg) {
got_level = l;
got = msg;
});
Void::Log::set_sink(
[&](Void::Log::Level l, auto, std::string_view msg, auto) {
got_level = l;
got = msg;
});
Void::Log::warn("m", "answer = {}", 42);
Void::Testing::expect(got_level == Void::Log::Level::Warning);
@@ -158,7 +160,7 @@ Void::Testing::Test disabled_calls_do_not_format()
// Sink present but level below the global minimum: still nothing.
int calls = 0;
Void::Log::set_sink([&](auto, auto, auto) { ++calls; });
Void::Log::set_sink([&](auto, auto, auto, auto) { ++calls; });
Void::Log::set_min_level(Void::Log::Level::Error);
Void::Log::debug("m", "{}", FormatProbe{&formatted});
Void::Testing::expect_eq(formatted, 0);
@@ -176,7 +178,7 @@ Void::Testing::Test global_min_level_filters()
{
SinkGuard guard;
int calls = 0;
Void::Log::set_sink([&](auto, auto, auto) { ++calls; });
Void::Log::set_sink([&](auto, auto, auto, auto) { ++calls; });
Void::Log::set_min_level(Void::Log::Level::Warning);
Void::Log::info("m", "dropped");
@@ -189,7 +191,7 @@ Void::Testing::Test disabled_level_silences_everything()
{
SinkGuard guard;
int calls = 0;
Void::Log::set_sink([&](auto, auto, auto) { ++calls; });
Void::Log::set_sink([&](auto, auto, auto, auto) { ++calls; });
Void::Log::set_min_level(Void::Log::Level::Disabled);
Void::Log::fatal("m", "still dropped");
@@ -200,7 +202,7 @@ Void::Testing::Test module_override_lowers_and_raises()
{
SinkGuard guard;
int calls = 0;
Void::Log::set_sink([&](auto, auto, auto) { ++calls; });
Void::Log::set_sink([&](auto, auto, auto, auto) { ++calls; });
Void::Log::set_min_level(Void::Log::Level::Warning);
// Lower the threshold for one module only.
@@ -222,7 +224,7 @@ Void::Testing::Test enabled_reflects_configuration()
Void::Testing::expect(
!Void::Log::enabled(Void::Log::Level::Fatal, "m")); // no sink
Void::Log::set_sink([](auto, auto, auto) {});
Void::Log::set_sink([](auto, auto, auto, auto) {});
Void::Log::set_min_level(Void::Log::Level::Info);
Void::Testing::expect(Void::Log::enabled(Void::Log::Level::Info, "m"));
Void::Testing::expect(!Void::Log::enabled(Void::Log::Level::Debug, "m"));