From e12feda1272922f6ad3567dd27509f0ec53d3a7b Mon Sep 17 00:00:00 2001 From: Stefan Boberg Date: Mon, 23 Mar 2026 12:53:58 +0100 Subject: Logger simplification (#883) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - **`Logger` now holds a single `SinkPtr`** instead of a `std::vector`. The `SetSinks`/`AddSink` API is replaced with a single `SetSink`. This removes complexity from `Logger` itself and makes `Clone()` cheaper (no vector copy). - **New `BroadcastSink`** (`zencore/logging/broadcastsink.h`) acts as a thread-safe, shared indirection point that fans out to a dynamic list of child sinks. Adding or removing a child sink via `AddSink`/`RemoveSink` is immediately visible to every `Logger` that holds a reference to it — including cloned loggers — without requiring each logger to be updated individually. - **`GetDefaultBroadcastSink()`** (exposed from `zenutil/logging.h`) gives server-layer code access to the shared broadcast sink so it can register optional sinks (OTel, TCP log stream) after logging is initialized, without going through `Default()->AddSink()`. ### Motivation Previously, dynamically adding sinks post-initialization mutated the default logger's internal sink vector directly. This was fragile: cloned loggers (created before `AddSink` was called) would not pick up the new sinks. `BroadcastSink` fixes this by making the sink list a shared, mutable object that all loggers sharing the same broadcast instance observe uniformly. --- src/zencore/logging.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/zencore/logging.cpp') diff --git a/src/zencore/logging.cpp b/src/zencore/logging.cpp index 3206e380b..828bea6ed 100644 --- a/src/zencore/logging.cpp +++ b/src/zencore/logging.cpp @@ -345,7 +345,7 @@ SuppressConsoleLog() } SinkPtr NullSinkPtr(new NullSink()); - ConLogger = Ref(new Logger("console", std::vector{NullSinkPtr})); + ConLogger = Ref(new Logger("console", NullSinkPtr)); Registry::Instance().Register(ConLogger); } @@ -391,7 +391,7 @@ ConsoleLog() { SinkPtr ConsoleSink(new AnsiColorStdoutSink()); ConsoleSink->SetFormatter(std::make_unique()); - ConLogger = Ref(new Logger("console", std::vector{ConsoleSink})); + ConLogger = Ref(new Logger("console", ConsoleSink)); Registry::Instance().Register(ConLogger); } }); -- cgit v1.2.3