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/utils.cpp | 102 -------------------------------------- 1 file changed, 102 deletions(-) delete mode 100644 thirdparty/spdlog/tests/utils.cpp (limited to 'thirdparty/spdlog/tests/utils.cpp') diff --git a/thirdparty/spdlog/tests/utils.cpp b/thirdparty/spdlog/tests/utils.cpp deleted file mode 100644 index 405b5e5a2..000000000 --- a/thirdparty/spdlog/tests/utils.cpp +++ /dev/null @@ -1,102 +0,0 @@ -#include "includes.h" - -#ifdef _WIN32 - #include -#else - #include - #include -#endif - -void prepare_logdir() { - spdlog::drop_all(); -#ifdef _WIN32 - system("rmdir /S /Q test_logs"); -#else - auto rv = system("rm -rf test_logs"); - if (rv != 0) { - throw std::runtime_error("Failed to rm -rf test_logs"); - } -#endif -} - -std::string file_contents(const std::string &filename) { - std::ifstream ifs(filename, std::ios_base::binary); - if (!ifs) { - throw std::runtime_error("Failed open file "); - } - return std::string((std::istreambuf_iterator(ifs)), (std::istreambuf_iterator())); -} - -std::size_t count_lines(const std::string &filename) { - std::ifstream ifs(filename); - if (!ifs) { - throw std::runtime_error("Failed open file "); - } - - std::string line; - size_t counter = 0; - while (std::getline(ifs, line)) counter++; - return counter; -} - -void require_message_count(const std::string &filename, const std::size_t messages) { - if (strlen(spdlog::details::os::default_eol) == 0) { - REQUIRE(count_lines(filename) == 1); - } else { - REQUIRE(count_lines(filename) == messages); - } -} - -std::size_t get_filesize(const std::string &filename) { - std::ifstream ifs(filename, std::ifstream::ate | std::ifstream::binary); - if (!ifs) { - throw std::runtime_error("Failed open file " + filename); - } - return static_cast(ifs.tellg()); -} - -// source: https://stackoverflow.com/a/2072890/192001 -bool ends_with(std::string const &value, std::string const &ending) { - if (ending.size() > value.size()) { - return false; - } - return std::equal(ending.rbegin(), ending.rend(), value.rbegin()); -} - -#ifdef _WIN32 -// Based on: https://stackoverflow.com/a/37416569/192001 -std::size_t count_files(const std::string &folder) { - size_t counter = 0; - WIN32_FIND_DATAA ffd; - - // Start iterating over the files in the folder directory. - HANDLE hFind = ::FindFirstFileA((folder + "\\*").c_str(), &ffd); - if (hFind != INVALID_HANDLE_VALUE) { - do // Managed to locate and create an handle to that folder. - { - if (ffd.cFileName[0] != '.') counter++; - } while (::FindNextFileA(hFind, &ffd) != 0); - ::FindClose(hFind); - } else { - throw std::runtime_error("Failed open folder " + folder); - } - - return counter; -} -#else -// Based on: https://stackoverflow.com/a/2802255/192001 -std::size_t count_files(const std::string &folder) { - size_t counter = 0; - DIR *dp = opendir(folder.c_str()); - if (dp == nullptr) { - throw std::runtime_error("Failed open folder " + folder); - } - - struct dirent *ep = nullptr; - while ((ep = readdir(dp)) != nullptr) { - if (ep->d_name[0] != '.') counter++; - } - (void)closedir(dp); - return counter; -} -#endif -- cgit v1.2.3