From d5a792da732b85d8e80298c67cfa9c6696fe42db Mon Sep 17 00:00:00 2001 From: Sean Harmer Date: Tue, 5 Dec 2023 15:52:31 +0000 Subject: [PATCH] Improve logger helper So that we need a factory that checks the spdlog registry in its own dll before creating a new logger. Or, if no factory is set we check the KDUtils registry. Call sites should not worry about checkign via spdlog::get() themselves as this helper and any installed factory should now do it instead. This will ensure the same registry is checked as is used when creating each logger. Change-Id: I24399e7ca778ddd310d6074300e70143ca3d2d9f Reviewed-on: https://codereview.kdab.com/c/kdab/kdutils/+/134715 Reviewed-by: Paul Lemire --- src/KDUtils/logging.cpp | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/KDUtils/logging.cpp b/src/KDUtils/logging.cpp index aef590a..75a1ee8 100644 --- a/src/KDUtils/logging.cpp +++ b/src/KDUtils/logging.cpp @@ -18,13 +18,19 @@ std::shared_ptr Logger::logger(const std::string &name) { std::shared_ptr logger; if (ms_loggerFactory) { + // Use the factory set by the application which should check + // its own spdlog registry first before creating a new logger. logger = ms_loggerFactory(name); } else { + // No factory set, use the spdlog registry from KDUtils + logger = spdlog::get(name); + if (!logger) { #if defined(ANDROID) - logger = spdlog::android_logger_mt(name, name); + logger = spdlog::android_logger_mt(name, name); #else - logger = spdlog::stdout_color_mt(name); + logger = spdlog::stdout_color_mt(name); #endif + } } return logger; }