Added the factory function to the registry directly

pull/1216/head
Stefano Caiazza 6 years ago
parent 2d81721f11
commit 88ced28c59

@ -84,6 +84,16 @@ public:
void set_automatic_registration(bool automatic_regsistration); void set_automatic_registration(bool automatic_regsistration);
// Factory function to create a new logger and register it in this registry
template<typename Sink, typename... SinkArgs>
std::shared_ptr<spdlog::logger> create(std::string logger_name, SinkArgs&& ... args)
{
auto sink = std::make_shared<Sink>(std::forward<SinkArgs>(args)...);
auto new_logger = std::make_shared<spdlog::logger>(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 // The unique global instance of the registry, usefult to access it
// from the global scope. NOTE It doesn't make it a singleton // from the global scope. NOTE It doesn't make it a singleton
static registry &instance(); static registry &instance();

@ -15,10 +15,8 @@ struct synchronous_factory
template<typename Sink, typename... SinkArgs> template<typename Sink, typename... SinkArgs>
static std::shared_ptr<spdlog::logger> create(std::string logger_name, SinkArgs &&... args) static std::shared_ptr<spdlog::logger> create(std::string logger_name, SinkArgs &&... args)
{ {
auto sink = std::make_shared<Sink>(std::forward<SinkArgs>(args)...); return details::registry::instance().create<Sink>(
auto new_logger = std::make_shared<spdlog::logger>(std::move(logger_name), std::move(sink)); std::move(logger_name), std::forward<SinkArgs>(args)...);
details::registry::instance().initialize_logger(new_logger);
return new_logger;
} }
}; };
} // namespace spdlog } // namespace spdlog
Loading…
Cancel
Save