From b5a5edacbe64b30a4414d10988fbf2b46f0abc81 Mon Sep 17 00:00:00 2001 From: xaqq Date: Mon, 1 Dec 2014 15:51:57 +0100 Subject: [PATCH] Add a drop() method to remove logger from the registry This commits allows the user to drop the registry reference to a logger, allowing deletion of logger at any time. --- include/spdlog/details/registry.h | 5 +++++ include/spdlog/details/spdlog_impl.h | 4 ++++ include/spdlog/spdlog.h | 4 ++++ 3 files changed, 13 insertions(+) diff --git a/include/spdlog/details/registry.h b/include/spdlog/details/registry.h index 9cf14352..104ac18f 100644 --- a/include/spdlog/details/registry.h +++ b/include/spdlog/details/registry.h @@ -72,6 +72,11 @@ public: return new_logger; } + void drop(const std::string &logger_name) + { + std::lock_guard lock(_mutex); + _loggers.erase(logger_name); + } std::shared_ptr create(const std::string& logger_name, sinks_init_list sinks) { diff --git a/include/spdlog/details/spdlog_impl.h b/include/spdlog/details/spdlog_impl.h index 140b66a0..a3a76111 100644 --- a/include/spdlog/details/spdlog_impl.h +++ b/include/spdlog/details/spdlog_impl.h @@ -37,6 +37,10 @@ inline std::shared_ptr spdlog::get(const std::string& name) return details::registry::instance().get(name); } +inline void spdlog::drop(const std::string &name) +{ + details::registry::instance().drop(name); +} // Create multi/single threaded rotating file logger inline std::shared_ptr spdlog::rotating_logger_mt(const std::string& logger_name, const std::string& filename, size_t max_file_size, size_t max_files, bool auto_flush) diff --git a/include/spdlog/spdlog.h b/include/spdlog/spdlog.h index c153b93f..6db7ca3d 100644 --- a/include/spdlog/spdlog.h +++ b/include/spdlog/spdlog.h @@ -42,6 +42,10 @@ namespace spdlog // logger.info() << "This is another message" << x << y << z; std::shared_ptr get(const std::string& name); +// +// Drop the reference to this logger. +// +void drop(const std::string &name); // // Set global formatting