Brought the registry constructor in public

pull/1216/head
Stefano Caiazza 6 years ago
parent 45a18a61c6
commit 2d81721f11

@ -8,7 +8,6 @@
#endif #endif
#include "spdlog/common.h" #include "spdlog/common.h"
#include "spdlog/details/periodic_worker.h"
#include "spdlog/logger.h" #include "spdlog/logger.h"
#include "spdlog/details/pattern_formatter.h" #include "spdlog/details/pattern_formatter.h"

@ -9,6 +9,7 @@
// This class is thread safe // This class is thread safe
#include "spdlog/common.h" #include "spdlog/common.h"
#include "spdlog/details/periodic_worker.h"
#include <chrono> #include <chrono>
#include <functional> #include <functional>
@ -27,6 +28,10 @@ class periodic_worker;
class registry class registry
{ {
public: public:
// Default constructor
registry();
~registry() = default;
registry(const registry &) = delete; registry(const registry &) = delete;
registry &operator=(const registry &) = delete; registry &operator=(const registry &) = delete;
@ -79,12 +84,11 @@ public:
void set_automatic_registration(bool automatic_regsistration); 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(); static registry &instance();
private: private:
registry();
~registry() = default;
void throw_if_exists_(const std::string &logger_name); void throw_if_exists_(const std::string &logger_name);
void register_logger_(std::shared_ptr<logger> new_logger); void register_logger_(std::shared_ptr<logger> new_logger);
std::mutex logger_map_mutex_, flusher_mutex_; std::mutex logger_map_mutex_, flusher_mutex_;

@ -114,3 +114,22 @@ TEST_CASE("disable automatic registration", "[registry]")
spdlog::set_level(spdlog::level::info); spdlog::set_level(spdlog::level::info);
spdlog::set_automatic_registration(true); 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<spdlog::sinks::null_sink_mt>();
auto new_logger = std::make_shared<spdlog::logger>(tested_logger_name, std::move(sink));
Local.initialize_logger(new_logger);
REQUIRE(Local.get(tested_logger_name) != nullptr);
}
}

Loading…
Cancel
Save