diff --git a/include/spdlog/details/registry-inl.h b/include/spdlog/details/registry-inl.h index a23655f0..da4a7de9 100644 --- a/include/spdlog/details/registry-inl.h +++ b/include/spdlog/details/registry-inl.h @@ -259,22 +259,6 @@ SPDLOG_INLINE void registry::register_logger_(std::shared_ptr new_logger auto logger_name = new_logger->name(); throw_if_exists_(logger_name); loggers_[logger_name] = std::move(new_logger); - - const auto& logger = loggers_[logger_name]; - for (const auto& on_registration_callback : on_registration_callbacks_) { - on_registration_callback(logger); - } -} - -SPDLOG_INLINE void registry::add_on_registration_callback( - const std::function)>& callback) { - std::lock_guard lock(logger_map_mutex_); - on_registration_callbacks_.push_back(callback); -} - -SPDLOG_INLINE void registry::drop_all_on_registration_callbacks() { - std::lock_guard lock(logger_map_mutex_); - on_registration_callbacks_.clear(); } } // namespace details diff --git a/include/spdlog/details/registry.h b/include/spdlog/details/registry.h index cb3cc2ba..56a6886e 100644 --- a/include/spdlog/details/registry.h +++ b/include/spdlog/details/registry.h @@ -17,7 +17,6 @@ #include #include #include -#include namespace spdlog { class logger; @@ -93,10 +92,6 @@ public: void apply_logger_env_levels(std::shared_ptr new_logger); - void add_on_registration_callback(const std::function)>& callback); - - void drop_all_on_registration_callbacks(); - private: registry(); ~registry(); @@ -117,7 +112,6 @@ private: std::shared_ptr default_logger_; bool automatic_registration_ = true; size_t backtrace_n_messages_ = 0; - std::vector)>> on_registration_callbacks_; }; } // namespace details diff --git a/include/spdlog/spdlog-inl.h b/include/spdlog/spdlog-inl.h index 9959dbac..97c36222 100644 --- a/include/spdlog/spdlog-inl.h +++ b/include/spdlog/spdlog-inl.h @@ -89,12 +89,4 @@ SPDLOG_INLINE void apply_logger_env_levels(std::shared_ptr logger) { details::registry::instance().apply_logger_env_levels(std::move(logger)); } -SPDLOG_INLINE void add_on_registration_callback(const std::function&)>& callback) { - details::registry::instance().add_on_registration_callback(callback); -} - -SPDLOG_INLINE void drop_all_on_registration_callbacks() { - details::registry::instance().drop_all_on_registration_callbacks(); -} - } // namespace spdlog diff --git a/include/spdlog/spdlog.h b/include/spdlog/spdlog.h index dc077d69..a8afbcec 100644 --- a/include/spdlog/spdlog.h +++ b/include/spdlog/spdlog.h @@ -140,21 +140,6 @@ SPDLOG_API void set_default_logger(std::shared_ptr default_logge // spdlog::apply_logger_env_levels(mylogger); SPDLOG_API void apply_logger_env_levels(std::shared_ptr logger); -// Add a callback that is called whenever a logger is registered -// -// Useful for intercepting loggers that are dynamically created during the application's lifetime -// (e.g. from dynamically loaded libraries, etc.) -// Example: -// void my_on_registration_callback(const std::shared_ptr& logger) { -// logger->do_stuff(); -// } -// ... -// spdlog::add_on_registration_callback(my_on_registration_callback); -SPDLOG_API void add_on_registration_callback(const std::function&)>& callback); - -// Clear all callbacks that were added to intercept registrations (see "add_on_registration_callback") -SPDLOG_API void drop_all_on_registration_callbacks(); - template inline void log(source_loc source, level::level_enum lvl, diff --git a/tests/test_registry.cpp b/tests/test_registry.cpp index 11a56539..69ec8f53 100644 --- a/tests/test_registry.cpp +++ b/tests/test_registry.cpp @@ -110,30 +110,3 @@ TEST_CASE("disable automatic registration", "[registry]") { spdlog::set_level(spdlog::level::info); spdlog::set_automatic_registration(true); } - -TEST_CASE("add_on_registration_callback", "[registry]") { - std::vector registered_logger_names; - auto on_registration_callback = [&](std::shared_ptr logger) - { - registered_logger_names.push_back(logger->name()); - }; - spdlog::add_on_registration_callback(on_registration_callback); - - auto captured_registration_logger1 = spdlog::create("captured_registration_logger1"); - - spdlog::set_automatic_registration(false); - auto non_captured_registration_logger1 = spdlog::create("non_captured_registration_logger1"); - - auto captured_registration_logger2 = spdlog::create("captured_registration_logger2"); - spdlog::register_logger(captured_registration_logger2); - - spdlog::drop_all_on_registration_callbacks(); - auto non_captured_registration_logger2 = spdlog::create("non_captured_registration_logger2"); - spdlog::register_logger(non_captured_registration_logger2); - - // Check that only the automatically registered logged and the manually registered logger were captured - REQUIRE(registered_logger_names == std::vector({"captured_registration_logger1", "captured_registration_logger2"})); - - spdlog::set_level(spdlog::level::info); - spdlog::set_automatic_registration(true); -} \ No newline at end of file