diff --git a/CMakeLists.txt b/CMakeLists.txt index f0947445..9c905783 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -162,7 +162,7 @@ set(SPDLOG_HEADERS "include/spdlog/details/null_mutex.h" "include/spdlog/details/os.h" "include/spdlog/details/periodic_worker.h" - "include/spdlog/details/registry.h" + "include/spdlog/details/context.h" "include/spdlog/details/synchronous_factory.h" "include/spdlog/details/thread_pool.h" "include/spdlog/fmt/bin_to_hex.h" @@ -203,7 +203,7 @@ set(SPDLOG_SRCS "src/details/log_msg.cpp" "src/details/log_msg_buffer.cpp" "src/details/periodic_worker.cpp" - "src/details/registry.cpp" + "src/details/context.cpp" "src/details/thread_pool.cpp" "src/sinks/base_sink.cpp" "src/sinks/basic_file_sink.cpp" @@ -309,7 +309,7 @@ endif() # --------------------------------------------------------------------------------------- # spdlog private defines according to the options # --------------------------------------------------------------------------------------- -foreach(SPDLOG_OPTION +foreach(SPDLOG_OPTION SPDLOG_CLOCK_COARSE SPDLOG_PREVENT_CHILD_FD SPDLOG_NO_THREAD_ID diff --git a/example/example.cpp b/example/example.cpp index 1de2b063..57d269cb 100644 --- a/example/example.cpp +++ b/example/example.cpp @@ -73,10 +73,6 @@ int main(int, char *[]) { file_events_example(); replace_default_logger_example(); - // Flush all *registered* loggers using a worker thread every 3 seconds. - // note: registered loggers *must* be thread safe for this to work correctly! - spdlog::flush_every(std::chrono::seconds(3)); - // Apply some function on all registered loggers spdlog::apply_all([&](std::shared_ptr l) { l->info("End of example."); }); @@ -192,10 +188,6 @@ void trace_example() { SPDLOG_TRACE("Some trace message.. {} ,{}", 1, 3.23); // debug from default logger SPDLOG_DEBUG("Some debug message.. {} ,{}", 1, 3.23); - - // trace from logger object - auto logger = spdlog::get("file_logger"); - SPDLOG_LOGGER_TRACE(logger, "another trace message"); } // stopwatch example diff --git a/include/spdlog/async.h b/include/spdlog/async.h index fbecff47..c8fa5168 100644 --- a/include/spdlog/async.h +++ b/include/spdlog/async.h @@ -19,7 +19,7 @@ #include #include "./async_logger.h" -#include "./details/registry.h" +#include "./details/context.h" #include "./details/thread_pool.h" namespace spdlog { @@ -35,7 +35,7 @@ template struct async_factory_impl { template static std::shared_ptr create(std::string logger_name, SinkArgs &&...args) { - auto ®istry_inst = details::registry::instance(); + auto ®istry_inst = details::context::instance(); // create global thread pool if not already exists auto &mutex = registry_inst.tp_mutex(); @@ -72,7 +72,7 @@ inline void init_thread_pool(size_t q_size, std::function on_thread_start, std::function on_thread_stop) { auto tp = std::make_shared(q_size, thread_count, on_thread_start, on_thread_stop); - details::registry::instance().set_tp(std::move(tp)); + details::context::instance().set_tp(std::move(tp)); } inline void init_thread_pool(size_t q_size, size_t thread_count, std::function on_thread_start) { @@ -84,5 +84,5 @@ inline void init_thread_pool(size_t q_size, size_t thread_count) { } // get the global thread pool. -inline std::shared_ptr thread_pool() { return details::registry::instance().get_tp(); } +inline std::shared_ptr thread_pool() { return details::context::instance().get_tp(); } } // namespace spdlog diff --git a/include/spdlog/cfg/env.h b/include/spdlog/cfg/env.h index 918ce662..ff1f0c9b 100644 --- a/include/spdlog/cfg/env.h +++ b/include/spdlog/cfg/env.h @@ -2,8 +2,8 @@ // Distributed under the MIT License (http://opensource.org/licenses/MIT) #pragma once +#include "../details/context.h" #include "../details/os.h" -#include "../details/registry.h" #include "./helpers.h" // diff --git a/include/spdlog/details/registry.h b/include/spdlog/details/context.h similarity index 77% rename from include/spdlog/details/registry.h rename to include/spdlog/details/context.h index 30ff88ea..45ebeba0 100644 --- a/include/spdlog/details/registry.h +++ b/include/spdlog/details/context.h @@ -25,19 +25,15 @@ class logger; namespace details { class thread_pool; -class SPDLOG_API registry { +class SPDLOG_API context { public: using log_levels = std::unordered_map; - static registry &instance(); - registry(const registry &) = delete; - registry &operator=(const registry &) = delete; + static context &instance(); + context(const context &) = delete; + context &operator=(const context &) = delete; - void register_logger(std::shared_ptr new_logger); void initialize_logger(std::shared_ptr new_logger); - std::shared_ptr get(const std::string &logger_name); - std::shared_ptr get(std::string_view logger_name); - std::shared_ptr get(const char *logger_name); std::shared_ptr default_logger(); // Return raw ptr to the default logger. @@ -62,18 +58,6 @@ public: void flush_on(level level); - template - void flush_every(std::chrono::duration interval) { - std::lock_guard lock(flusher_mutex_); - auto clbk = [this]() { this->flush_all(); }; - periodic_flusher_ = std::make_unique(clbk, interval); - } - - std::unique_ptr &get_flusher() { - std::lock_guard lock(flusher_mutex_); - return periodic_flusher_; - } - void set_error_handler(err_handler handler); void apply_all(const std::function)> &fun); @@ -97,8 +81,8 @@ public: void apply_logger_env_levels(std::shared_ptr new_logger); private: - registry(); - ~registry(); + context(); + ~context(); void throw_if_exists_(const std::string &logger_name); void register_logger_(std::shared_ptr new_logger); diff --git a/include/spdlog/details/synchronous_factory.h b/include/spdlog/details/synchronous_factory.h index 6baff7d1..391231e3 100644 --- a/include/spdlog/details/synchronous_factory.h +++ b/include/spdlog/details/synchronous_factory.h @@ -3,7 +3,7 @@ #pragma once -#include "./registry.h" +#include "./context.h" namespace spdlog { @@ -15,7 +15,7 @@ struct synchronous_factory { 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); + details::context::instance().initialize_logger(new_logger); return new_logger; } }; diff --git a/include/spdlog/spdlog.h b/include/spdlog/spdlog.h index 590e4a6f..cede04c2 100644 --- a/include/spdlog/spdlog.h +++ b/include/spdlog/spdlog.h @@ -16,7 +16,7 @@ #include #include "./common.h" -#include "./details/registry.h" +#include "./details/context.h" #include "./details/synchronous_factory.h" #include "./logger.h" @@ -71,13 +71,6 @@ SPDLOG_API bool should_log(level level); // Set global flush level SPDLOG_API void flush_on(level level); -// Start/Restart a periodic flusher thread -// Warning: Use only if all your loggers are thread safe! -template -inline void flush_every(std::chrono::duration interval) { - details::registry::instance().flush_every(interval); -} - // Set global error handler SPDLOG_API void set_error_handler(void (*handler)(const std::string &msg)); diff --git a/src/cfg/helpers.cpp b/src/cfg/helpers.cpp index 29e9c961..026cb222 100644 --- a/src/cfg/helpers.cpp +++ b/src/cfg/helpers.cpp @@ -8,7 +8,7 @@ #include #include -#include "spdlog/details/registry.h" +#include "spdlog/details/context.h" namespace spdlog { namespace cfg { @@ -91,7 +91,7 @@ void load_levels(const std::string &input) { } } - details::registry::instance().set_levels(std::move(levels), global_level_found ? &global_level : nullptr); + details::context::instance().set_levels(std::move(levels), global_level_found ? &global_level : nullptr); } } // namespace helpers diff --git a/src/details/registry.cpp b/src/details/context.cpp similarity index 66% rename from src/details/registry.cpp rename to src/details/context.cpp index 2055b739..d0da8eb9 100644 --- a/src/details/registry.cpp +++ b/src/details/context.cpp @@ -1,9 +1,8 @@ // Copyright(c) 2015-present, Gabi Melman & spdlog contributors. // Distributed under the MIT License (http://opensource.org/licenses/MIT) -#include "spdlog/details/registry.h" - #include "spdlog/common.h" +#include "spdlog/details/context.h" #include "spdlog/logger.h" #include "spdlog/pattern_formatter.h" @@ -27,7 +26,7 @@ static constexpr size_t small_map_threshold = 10; namespace spdlog { namespace details { -registry::registry() +context::context() : formatter_(new pattern_formatter()) { #ifndef SPDLOG_DISABLE_DEFAULT_LOGGER // create default logger (ansicolor_stdout_sink_mt or wincolor_stdout_sink_mt in windows). @@ -43,14 +42,9 @@ registry::registry() #endif // SPDLOG_DISABLE_DEFAULT_LOGGER } -registry::~registry() = default; +context::~context() = default; -void registry::register_logger(std::shared_ptr new_logger) { - std::lock_guard lock(logger_map_mutex_); - register_logger_(std::move(new_logger)); -} - -void registry::initialize_logger(std::shared_ptr new_logger) { +void context::initialize_logger(std::shared_ptr new_logger) { std::lock_guard lock(logger_map_mutex_); new_logger->set_formatter(formatter_->clone()); @@ -70,41 +64,7 @@ void registry::initialize_logger(std::shared_ptr new_logger) { } } -// if the map is small do a sequential search, otherwise use the standard find() -std::shared_ptr registry::get(const std::string &logger_name) { - std::lock_guard lock(logger_map_mutex_); - if (loggers_.size() <= small_map_threshold) { - for (const auto &[key, val] : loggers_) { - if (logger_name == key) { - return val; - } - } - return nullptr; - } - auto found = loggers_.find(logger_name); - return found == loggers_.end() ? nullptr : found->second; -} - -// if the map is small do a sequential search and avoid creating string for find(logger_name) -// otherwise use the standard find() -std::shared_ptr registry::get(std::string_view logger_name) { - std::lock_guard lock(logger_map_mutex_); - if (loggers_.size() <= small_map_threshold) { - for (const auto &[key, val] : loggers_) { - if (logger_name == key) { - return val; - } - } - return nullptr; - } - // otherwise use the normal map lookup - const auto found = loggers_.find(std::string(logger_name)); - return found == loggers_.end() ? nullptr : found->second; -} - -std::shared_ptr registry::get(const char *logger_name) { return get(std::string_view(logger_name)); } - -std::shared_ptr registry::default_logger() { +std::shared_ptr context::default_logger() { std::lock_guard lock(logger_map_mutex_); return default_logger_; } @@ -113,11 +73,11 @@ std::shared_ptr registry::default_logger() { // To be used directly by the spdlog default api (e.g. spdlog::info) // This make the default API faster, but cannot be used concurrently with set_default_logger(). // e.g do not call set_default_logger() from one thread while calling spdlog::info() from another. -logger *registry::get_default_raw() const { return default_logger_.get(); } +logger *context::get_default_raw() const { return default_logger_.get(); } // set default logger. // default logger is stored in default_logger_ (for faster retrieval) and in the loggers_ map. -void registry::set_default_logger(std::shared_ptr new_default_logger) { +void context::set_default_logger(std::shared_ptr new_default_logger) { std::lock_guard lock(logger_map_mutex_); if (new_default_logger != nullptr) { loggers_[new_default_logger->name()] = new_default_logger; @@ -125,18 +85,18 @@ void registry::set_default_logger(std::shared_ptr new_default_logger) { default_logger_ = std::move(new_default_logger); } -void registry::set_tp(std::shared_ptr tp) { +void context::set_tp(std::shared_ptr tp) { std::lock_guard lock(tp_mutex_); tp_ = std::move(tp); } -std::shared_ptr registry::get_tp() { +std::shared_ptr context::get_tp() { std::lock_guard lock(tp_mutex_); return tp_; } // Set global formatter. Each sink in each logger will get a clone of this object -void registry::set_formatter(std::unique_ptr formatter) { +void context::set_formatter(std::unique_ptr formatter) { std::lock_guard lock(logger_map_mutex_); formatter_ = std::move(formatter); for (auto &l : loggers_) { @@ -144,7 +104,7 @@ void registry::set_formatter(std::unique_ptr formatter) { } } -void registry::set_level(level level) { +void context::set_level(level level) { std::lock_guard lock(logger_map_mutex_); for (auto &l : loggers_) { l.second->set_level(level); @@ -152,7 +112,7 @@ void registry::set_level(level level) { global_log_level_ = level; } -void registry::flush_on(level level) { +void context::flush_on(level level) { std::lock_guard lock(logger_map_mutex_); for (auto &l : loggers_) { l.second->flush_on(level); @@ -160,7 +120,7 @@ void registry::flush_on(level level) { flush_level_ = level; } -void registry::set_error_handler(err_handler handler) { +void context::set_error_handler(err_handler handler) { std::lock_guard lock(logger_map_mutex_); for (auto &l : loggers_) { l.second->set_error_handler(handler); @@ -168,21 +128,21 @@ void registry::set_error_handler(err_handler handler) { err_handler_ = std::move(handler); } -void registry::apply_all(const std::function)> &fun) { +void context::apply_all(const std::function)> &fun) { std::lock_guard lock(logger_map_mutex_); for (auto &l : loggers_) { fun(l.second); } } -void registry::flush_all() { +void context::flush_all() { std::lock_guard lock(logger_map_mutex_); for (auto &l : loggers_) { l.second->flush(); } } -void registry::drop(const std::string &logger_name) { +void context::drop(const std::string &logger_name) { std::lock_guard lock(logger_map_mutex_); auto is_default_logger = default_logger_ && default_logger_->name() == logger_name; loggers_.erase(logger_name); @@ -191,14 +151,14 @@ void registry::drop(const std::string &logger_name) { } } -void registry::drop_all() { +void context::drop_all() { std::lock_guard lock(logger_map_mutex_); loggers_.clear(); default_logger_.reset(); } // clean all resources and threads started by the registry -void registry::shutdown() { +void context::shutdown() { { std::lock_guard lock(flusher_mutex_); periodic_flusher_.reset(); @@ -212,14 +172,14 @@ void registry::shutdown() { } } -std::recursive_mutex ®istry::tp_mutex() { return tp_mutex_; } +std::recursive_mutex &context::tp_mutex() { return tp_mutex_; } -void registry::set_automatic_registration(bool automatic_registration) { +void context::set_automatic_registration(bool automatic_registration) { std::lock_guard lock(logger_map_mutex_); automatic_registration_ = automatic_registration; } -void registry::set_levels(log_levels levels, level *global_level) { +void context::set_levels(log_levels levels, level *global_level) { std::lock_guard lock(logger_map_mutex_); log_levels_ = std::move(levels); auto global_level_requested = global_level != nullptr; @@ -235,25 +195,25 @@ void registry::set_levels(log_levels levels, level *global_level) { } } -registry ®istry::instance() { - static registry s_instance; +context &context::instance() { + static context s_instance; return s_instance; } -void registry::apply_logger_env_levels(std::shared_ptr new_logger) { +void context::apply_logger_env_levels(std::shared_ptr new_logger) { std::lock_guard lock(logger_map_mutex_); auto it = log_levels_.find(new_logger->name()); auto new_level = it != log_levels_.end() ? it->second : global_log_level_; new_logger->set_level(new_level); } -void registry::throw_if_exists_(const std::string &logger_name) { +void context::throw_if_exists_(const std::string &logger_name) { if (loggers_.find(logger_name) != loggers_.end()) { throw_spdlog_ex("logger with name '" + logger_name + "' already exists"); } } -void registry::register_logger_(std::shared_ptr new_logger) { +void context::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); diff --git a/src/spdlog.cpp b/src/spdlog.cpp index f7e125ff..60bcfdd5 100644 --- a/src/spdlog.cpp +++ b/src/spdlog.cpp @@ -12,16 +12,10 @@ namespace spdlog { -void initialize_logger(std::shared_ptr logger) { details::registry::instance().initialize_logger(std::move(logger)); } - -std::shared_ptr get(const std::string &name) { return details::registry::instance().get(name); } - -std::shared_ptr get(std::string_view name) { return details::registry::instance().get(name); } - -std::shared_ptr get(const char *name) { return details::registry::instance().get(name); } +void initialize_logger(std::shared_ptr logger) { details::context::instance().initialize_logger(std::move(logger)); } void set_formatter(std::unique_ptr formatter) { - details::registry::instance().set_formatter(std::move(formatter)); + details::context::instance().set_formatter(std::move(formatter)); } void set_pattern(std::string pattern, pattern_time_type time_type) { @@ -32,35 +26,33 @@ level get_level() { return default_logger_raw()->log_level(); } bool should_log(level level) { return default_logger_raw()->should_log(level); } -void set_level(level level) { details::registry::instance().set_level(level); } +void set_level(level level) { details::context::instance().set_level(level); } -void flush_on(level level) { details::registry::instance().flush_on(level); } +void flush_on(level level) { details::context::instance().flush_on(level); } -void set_error_handler(void (*handler)(const std::string &msg)) { details::registry::instance().set_error_handler(handler); } +void set_error_handler(void (*handler)(const std::string &msg)) { details::context::instance().set_error_handler(handler); } -void register_logger(std::shared_ptr logger) { details::registry::instance().register_logger(std::move(logger)); } +void apply_all(const std::function)> &fun) { details::context::instance().apply_all(fun); } -void apply_all(const std::function)> &fun) { details::registry::instance().apply_all(fun); } +void drop(const std::string &name) { details::context::instance().drop(name); } -void drop(const std::string &name) { details::registry::instance().drop(name); } +void drop_all() { details::context::instance().drop_all(); } -void drop_all() { details::registry::instance().drop_all(); } - -void shutdown() { details::registry::instance().shutdown(); } +void shutdown() { details::context::instance().shutdown(); } void set_automatic_registration(bool automatic_registration) { - details::registry::instance().set_automatic_registration(automatic_registration); + details::context::instance().set_automatic_registration(automatic_registration); } -std::shared_ptr default_logger() { return details::registry::instance().default_logger(); } +std::shared_ptr default_logger() { return details::context::instance().default_logger(); } -spdlog::logger *default_logger_raw() { return details::registry::instance().get_default_raw(); } +spdlog::logger *default_logger_raw() { return details::context::instance().get_default_raw(); } void set_default_logger(std::shared_ptr default_logger) { - details::registry::instance().set_default_logger(std::move(default_logger)); + details::context::instance().set_default_logger(std::move(default_logger)); } void apply_logger_env_levels(std::shared_ptr logger) { - details::registry::instance().apply_logger_env_levels(std::move(logger)); + details::context::instance().apply_logger_env_levels(std::move(logger)); } } // namespace spdlog diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 647fff0f..8a699fab 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -34,8 +34,7 @@ set(SPDLOG_UTESTS_SOURCES test_misc.cpp test_pattern_formatter.cpp test_async.cpp - test_registry.cpp - test_macros.cpp + test_macros.cpp utils.cpp main.cpp test_mpmc_q.cpp diff --git a/tests/test_async.cpp b/tests/test_async.cpp index e31ec953..639b5e32 100644 --- a/tests/test_async.cpp +++ b/tests/test_async.cpp @@ -89,16 +89,6 @@ TEST_CASE("flush", "[async]") { REQUIRE(test_sink->flush_counter() == 1); } -TEST_CASE("async periodic flush", "[async]") { - auto logger = spdlog::create_async("as"); - auto test_sink = std::static_pointer_cast(logger->sinks()[0]); - - spdlog::flush_every(std::chrono::seconds(1)); - std::this_thread::sleep_for(std::chrono::milliseconds(1700)); - REQUIRE(test_sink->flush_counter() == 1); - spdlog::flush_every(std::chrono::seconds(0)); - spdlog::drop_all(); -} TEST_CASE("tp->wait_empty() ", "[async]") { auto test_sink = std::make_shared(); diff --git a/tests/test_misc.cpp b/tests/test_misc.cpp index a2b335c2..8b88062b 100644 --- a/tests/test_misc.cpp +++ b/tests/test_misc.cpp @@ -73,18 +73,6 @@ TEST_CASE("to_level_enum", "[convert_to_level_enum]") { REQUIRE(spdlog::level_from_str("null") == spdlog::level::off); } -TEST_CASE("periodic flush", "[periodic_flush]") { - using spdlog::sinks::test_sink_mt; - auto logger = spdlog::create("periodic_flush"); - auto test_sink = std::static_pointer_cast(logger->sinks()[0]); - - spdlog::flush_every(std::chrono::seconds(1)); - std::this_thread::sleep_for(std::chrono::milliseconds(1250)); - REQUIRE(test_sink->flush_counter() == 1); - spdlog::flush_every(std::chrono::seconds(0)); - spdlog::drop_all(); -} - TEST_CASE("clone-logger", "[clone]") { using spdlog::sinks::test_sink_mt; auto test_sink = std::make_shared(); diff --git a/tests/test_registry.cpp b/tests/test_registry.cpp deleted file mode 100644 index 467d944f..00000000 --- a/tests/test_registry.cpp +++ /dev/null @@ -1,129 +0,0 @@ -#include - -#include "includes.h" -#include "spdlog/sinks/daily_file_sink.h" -#include "spdlog/sinks/rotating_file_sink.h" - -static const char *const tested_logger_name = "null_logger"; -static const char *const tested_logger_name2 = "null_logger2"; - -TEST_CASE("register_drop", "[registry]") { - spdlog::drop_all(); - spdlog::create(tested_logger_name); - REQUIRE(spdlog::get(tested_logger_name) != nullptr); - // Throw if registering existing name - REQUIRE_THROWS_AS(spdlog::create(tested_logger_name), spdlog::spdlog_ex); -} - -TEST_CASE("explicit register", "[registry]") { - spdlog::drop_all(); - auto logger = std::make_shared(tested_logger_name, std::make_shared()); - spdlog::register_logger(logger); - REQUIRE(spdlog::get(tested_logger_name) != nullptr); - // Throw if registering existing name - REQUIRE_THROWS_AS(spdlog::create(tested_logger_name), spdlog::spdlog_ex); -} - -TEST_CASE("apply_all", "[registry]") { - spdlog::drop_all(); - auto logger = std::make_shared(tested_logger_name, std::make_shared()); - spdlog::register_logger(logger); - auto logger2 = std::make_shared(tested_logger_name2, std::make_shared()); - spdlog::register_logger(logger2); - - int counter = 0; - spdlog::apply_all([&counter](std::shared_ptr) { counter++; }); - REQUIRE(counter == 2); - - counter = 0; - spdlog::drop(tested_logger_name2); - spdlog::apply_all([&counter](std::shared_ptr l) { - REQUIRE(l->name() == tested_logger_name); - counter++; - }); - REQUIRE(counter == 1); -} - -TEST_CASE("drop", "[registry]") { - spdlog::drop_all(); - spdlog::create(tested_logger_name); - spdlog::drop(tested_logger_name); - REQUIRE_FALSE(spdlog::get(tested_logger_name)); -} - -TEST_CASE("drop-default", "[registry]") { - spdlog::set_default_logger(spdlog::null_logger_st(tested_logger_name)); - spdlog::drop(tested_logger_name); - REQUIRE_FALSE(spdlog::default_logger()); - REQUIRE_FALSE(spdlog::get(tested_logger_name)); -} - -TEST_CASE("drop_all", "[registry]") { - spdlog::drop_all(); - spdlog::create(tested_logger_name); - spdlog::create(tested_logger_name2); - spdlog::drop_all(); - REQUIRE_FALSE(spdlog::get(tested_logger_name)); - REQUIRE_FALSE(spdlog::get(tested_logger_name2)); - REQUIRE_FALSE(spdlog::default_logger()); -} - -TEST_CASE("drop non existing", "[registry]") { - spdlog::drop_all(); - spdlog::create(tested_logger_name); - spdlog::drop("some_name"); - REQUIRE_FALSE(spdlog::get("some_name")); - REQUIRE(spdlog::get(tested_logger_name)); - spdlog::drop_all(); -} - -TEST_CASE("default logger", "[registry]") { - spdlog::drop_all(); - spdlog::set_default_logger(spdlog::null_logger_st(tested_logger_name)); - REQUIRE(spdlog::get(tested_logger_name) == spdlog::default_logger()); - spdlog::drop_all(); -} - -TEST_CASE("set_default_logger(nullptr)", "[registry]") { - spdlog::set_default_logger(nullptr); - REQUIRE_FALSE(spdlog::default_logger()); -} - -TEST_CASE("disable automatic registration", "[registry]") { - // set some global parameters - spdlog::level level = spdlog::level::warn; - spdlog::set_level(level); - // but disable automatic registration - spdlog::set_automatic_registration(false); - auto logger1 = spdlog::create(tested_logger_name, SPDLOG_FILENAME_T("filename"), 11, 59); - auto logger2 = spdlog::create_async(tested_logger_name2); - // loggers should not be part of the registry - REQUIRE_FALSE(spdlog::get(tested_logger_name)); - REQUIRE_FALSE(spdlog::get(tested_logger_name2)); - // but make sure they are still initialized according to global defaults - REQUIRE(logger1->log_level() == level); - REQUIRE(logger2->log_level() == level); - spdlog::set_level(spdlog::level::info); - spdlog::set_automatic_registration(true); -} - -TEST_CASE("get(const char* name)", "[registry]") { - spdlog::drop_all(); - spdlog::create(tested_logger_name); - REQUIRE(spdlog::get(tested_logger_name) != nullptr); - spdlog::drop_all(); -} - -TEST_CASE("get(std::string_view name)", "[registry]") { - spdlog::drop_all(); - spdlog::create(tested_logger_name); - REQUIRE(spdlog::get(std::string_view(tested_logger_name)) != nullptr); - spdlog::drop_all(); -} - -TEST_CASE("get(std::string name)", "[registry]") { - spdlog::drop_all(); - spdlog::create(tested_logger_name); - REQUIRE(spdlog::get(std::string(tested_logger_name)) != nullptr); - spdlog::drop_all(); -}