diff --git a/include/spdlog/details/registry-inl.h b/include/spdlog/details/registry-inl.h index 075a0c7e..c5f3e2f4 100644 --- a/include/spdlog/details/registry-inl.h +++ b/include/spdlog/details/registry-inl.h @@ -8,7 +8,6 @@ #endif #include "spdlog/common.h" -#include "spdlog/details/periodic_worker.h" #include "spdlog/logger.h" #include "spdlog/details/pattern_formatter.h" diff --git a/include/spdlog/details/registry.h b/include/spdlog/details/registry.h index 35a117d9..628a7ea9 100644 --- a/include/spdlog/details/registry.h +++ b/include/spdlog/details/registry.h @@ -9,6 +9,7 @@ // This class is thread safe #include "spdlog/common.h" +#include "spdlog/details/periodic_worker.h" #include #include @@ -27,6 +28,10 @@ class periodic_worker; class registry { public: + // Default constructor + registry(); + ~registry() = default; + registry(const registry &) = delete; registry &operator=(const registry &) = delete; @@ -79,12 +84,11 @@ public: void set_automatic_registration(bool automatic_regsistration); + // The unique global instance of the registry, usefult to access it + // from the global scope. NOTE It doesn't make it a singleton static registry &instance(); private: - registry(); - ~registry() = default; - void throw_if_exists_(const std::string &logger_name); void register_logger_(std::shared_ptr new_logger); std::mutex logger_map_mutex_, flusher_mutex_; diff --git a/tests/test_registry.cpp b/tests/test_registry.cpp index 9759a505..6a4639af 100644 --- a/tests/test_registry.cpp +++ b/tests/test_registry.cpp @@ -114,3 +114,22 @@ TEST_CASE("disable automatic registration", "[registry]") spdlog::set_level(spdlog::level::info); spdlog::set_automatic_registration(true); } + +TEST_CASE("concrete registry and global instance", "[registry]") +{ + spdlog::details::registry Local{}; + auto& Global = spdlog::details::registry::instance(); + REQUIRE((&Global != &Local)); + + SECTION("register drop on local registry") + { + Local.drop_all(); + + auto sink = std::make_shared(); + auto new_logger = std::make_shared(tested_logger_name, std::move(sink)); + Local.initialize_logger(new_logger); + + REQUIRE(Local.get(tested_logger_name) != nullptr); + } + +}