From 19a117889c2db6b817af9458c04c04f324162e75 Mon Sep 17 00:00:00 2001 From: Stefan Boberg Date: Mon, 9 Mar 2026 10:50:47 +0100 Subject: Eliminate spdlog dependency (#773) Removes the vendored spdlog library (~12,000 lines) and replaces it with a purpose-built logging system in zencore (~1,800 lines). The new implementation provides the same functionality with fewer abstractions, no shared_ptr overhead, and full control over the logging pipeline. ### What changed **New logging core in zencore/logging/:** - LogMessage, Formatter, Sink, Logger, Registry - core abstractions matching spdlog's model but simplified - AnsiColorStdoutSink - ANSI color console output (replaces spdlog stdout_color_sink) - MsvcSink - OutputDebugString on Windows (replaces spdlog msvc_sink) - AsyncSink - async logging via BlockingQueue worker thread (replaces spdlog async_logger) - NullSink, MessageOnlyFormatter - utility types - Thread-safe timestamp caching in formatters using RwLock **Moved to zenutil/logging/:** - FullFormatter - full log formatting with timestamp, logger name, level, source location, multiline alignment - JsonFormatter - structured JSON log output - RotatingFileSink - rotating file sink with atomic size tracking **API changes:** - Log levels are now an enum (LogLevel) instead of int, eliminating the zen::logging::level namespace - LoggerRef no longer wraps shared_ptr - it holds a raw pointer with the registry owning lifetime - Logger error handler is wired through Registry and propagated to all loggers on registration - Logger::Log() now populates ThreadId on every message **Cleanup:** - Deleted thirdparty/spdlog/ entirely (110+ files) - Deleted full_test_formatter (was ~80% duplicate of FullFormatter) - Renamed snake_case classes to PascalCase (full_formatter -> FullFormatter, json_formatter -> JsonFormatter, sentry_sink -> SentrySink) - Removed spdlog from xmake dependency graph ### Build / test impact - zencore no longer depends on spdlog - zenutil and zenvfs xmake.lua updated to drop spdlog dep - zentelemetry xmake.lua updated to drop spdlog dep - All existing tests pass, no test changes required beyond formatter class renames --- thirdparty/spdlog/tests/test_eventlog.cpp | 75 ------------------------------- 1 file changed, 75 deletions(-) delete mode 100644 thirdparty/spdlog/tests/test_eventlog.cpp (limited to 'thirdparty/spdlog/tests/test_eventlog.cpp') diff --git a/thirdparty/spdlog/tests/test_eventlog.cpp b/thirdparty/spdlog/tests/test_eventlog.cpp deleted file mode 100644 index 702eabea1..000000000 --- a/thirdparty/spdlog/tests/test_eventlog.cpp +++ /dev/null @@ -1,75 +0,0 @@ -#if _WIN32 - - #include "includes.h" - #include "test_sink.h" - - #include "spdlog/sinks/win_eventlog_sink.h" - -static const LPCSTR TEST_SOURCE = "spdlog_test"; - -static void test_single_print(std::function do_log, - std::string const &expected_contents, - WORD expected_ev_type) { - using namespace std::chrono; - do_log(expected_contents); - const auto expected_time_generated = - duration_cast(system_clock::now().time_since_epoch()).count(); - - struct handle_t { - HANDLE handle_; - - ~handle_t() { - if (handle_) { - REQUIRE(CloseEventLog(handle_)); - } - } - } event_log{::OpenEventLogA(nullptr, TEST_SOURCE)}; - - REQUIRE(event_log.handle_); - - DWORD read_bytes{}, size_needed{}; - auto ok = ::ReadEventLogA(event_log.handle_, EVENTLOG_SEQUENTIAL_READ | EVENTLOG_BACKWARDS_READ, - 0, &read_bytes, 0, &read_bytes, &size_needed); - REQUIRE(!ok); - REQUIRE(::GetLastError() == ERROR_INSUFFICIENT_BUFFER); - - std::vector record_buffer(size_needed); - PEVENTLOGRECORD record = (PEVENTLOGRECORD)record_buffer.data(); - - ok = ::ReadEventLogA(event_log.handle_, EVENTLOG_SEQUENTIAL_READ | EVENTLOG_BACKWARDS_READ, 0, - record, size_needed, &read_bytes, &size_needed); - REQUIRE(ok); - - REQUIRE(record->NumStrings == 1); - REQUIRE(record->EventType == expected_ev_type); - REQUIRE((expected_time_generated - record->TimeGenerated) <= 3u); - - std::string message_in_log(((char *)record + record->StringOffset)); - REQUIRE(message_in_log == expected_contents + spdlog::details::os::default_eol); -} - -TEST_CASE("eventlog", "[eventlog]") { - using namespace spdlog; - - auto test_sink = std::make_shared(TEST_SOURCE); - - spdlog::logger test_logger("eventlog", test_sink); - test_logger.set_level(level::trace); - - test_sink->set_pattern("%v"); - - test_single_print([&test_logger](std::string const &msg) { test_logger.trace(msg); }, - "my trace message", EVENTLOG_SUCCESS); - test_single_print([&test_logger](std::string const &msg) { test_logger.debug(msg); }, - "my debug message", EVENTLOG_SUCCESS); - test_single_print([&test_logger](std::string const &msg) { test_logger.info(msg); }, - "my info message", EVENTLOG_INFORMATION_TYPE); - test_single_print([&test_logger](std::string const &msg) { test_logger.warn(msg); }, - "my warn message", EVENTLOG_WARNING_TYPE); - test_single_print([&test_logger](std::string const &msg) { test_logger.error(msg); }, - "my error message", EVENTLOG_ERROR_TYPE); - test_single_print([&test_logger](std::string const &msg) { test_logger.critical(msg); }, - "my critical message", EVENTLOG_ERROR_TYPE); -} - -#endif //_WIN32 -- cgit v1.2.3