diff --git a/include/spdlog/details/registry.h b/include/spdlog/details/registry.h index 628a7ea9..8c277486 100644 --- a/include/spdlog/details/registry.h +++ b/include/spdlog/details/registry.h @@ -84,6 +84,16 @@ public: void set_automatic_registration(bool automatic_regsistration); + // Factory function to create a new logger and register it in this registry + template + std::shared_ptr create(std::string logger_name, SinkArgs&& ... args) + { + auto sink = std::make_shared(std::forward(args)...); + auto new_logger = std::make_shared(std::move(logger_name), std::move(sink)); + this->initialize_logger(new_logger); + return new_logger; + } + // 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(); diff --git a/include/spdlog/details/synchronous_factory.h b/include/spdlog/details/synchronous_factory.h index 68f5c214..22328845 100644 --- a/include/spdlog/details/synchronous_factory.h +++ b/include/spdlog/details/synchronous_factory.h @@ -15,10 +15,8 @@ struct synchronous_factory template static std::shared_ptr create(std::string logger_name, SinkArgs &&... args) { - auto sink = std::make_shared(std::forward(args)...); - auto new_logger = std::make_shared(std::move(logger_name), std::move(sink)); - details::registry::instance().initialize_logger(new_logger); - return new_logger; + return details::registry::instance().create( + std::move(logger_name), std::forward(args)...); } }; } // namespace spdlog \ No newline at end of file