From 65eabb60b9a4f1b8514018fee607d070ff523d20 Mon Sep 17 00:00:00 2001 From: izlyforever Date: Sun, 10 Jul 2022 22:24:31 +0800 Subject: [PATCH] [FEAT] add api:overrun_counter --- include/spdlog/details/registry-inl.h | 10 ++++++++++ include/spdlog/details/registry.h | 3 +++ include/spdlog/details/thread_pool-inl.h | 1 + include/spdlog/details/thread_pool.h | 1 + include/spdlog/spdlog-inl.h | 5 +++++ include/spdlog/spdlog.h | 3 +++ 6 files changed, 23 insertions(+) diff --git a/include/spdlog/details/registry-inl.h b/include/spdlog/details/registry-inl.h index c55b5eea..92ebe355 100644 --- a/include/spdlog/details/registry-inl.h +++ b/include/spdlog/details/registry-inl.h @@ -9,6 +9,7 @@ #include #include +#include #include #include @@ -256,6 +257,15 @@ SPDLOG_INLINE void registry::shutdown() } } +SPDLOG_INLINE size_t registry::overrun_counter() +{ + std::lock_guard lock(tp_mutex_); + if (!tp_) { + return 0; + } + return tp_->overrun_counter(); +} + SPDLOG_INLINE std::recursive_mutex ®istry::tp_mutex() { return tp_mutex_; diff --git a/include/spdlog/details/registry.h b/include/spdlog/details/registry.h index 97473ea3..15c22b73 100644 --- a/include/spdlog/details/registry.h +++ b/include/spdlog/details/registry.h @@ -76,6 +76,9 @@ public: // clean all resources and threads started by the registry void shutdown(); + // get count of lost log + size_t overrun_counter(); + std::recursive_mutex &tp_mutex(); void set_automatic_registration(bool automatic_registration); diff --git a/include/spdlog/details/thread_pool-inl.h b/include/spdlog/details/thread_pool-inl.h index 369f30fe..1bccd688 100644 --- a/include/spdlog/details/thread_pool-inl.h +++ b/include/spdlog/details/thread_pool-inl.h @@ -7,6 +7,7 @@ # include #endif +#include #include #include diff --git a/include/spdlog/details/thread_pool.h b/include/spdlog/details/thread_pool.h index 52c569b8..33678084 100644 --- a/include/spdlog/details/thread_pool.h +++ b/include/spdlog/details/thread_pool.h @@ -15,6 +15,7 @@ namespace spdlog { class async_logger; +enum class async_overflow_policy; namespace details { diff --git a/include/spdlog/spdlog-inl.h b/include/spdlog/spdlog-inl.h index 2b875fae..b37921a9 100644 --- a/include/spdlog/spdlog-inl.h +++ b/include/spdlog/spdlog-inl.h @@ -102,6 +102,11 @@ SPDLOG_INLINE void shutdown() details::registry::instance().shutdown(); } +SPDLOG_INLINE size_t overrun_counter() +{ + return details::registry::instance().overrun_counter(); +} + SPDLOG_INLINE void set_automatic_registration(bool automatic_registration) { details::registry::instance().set_automatic_registration(automatic_registration); diff --git a/include/spdlog/spdlog.h b/include/spdlog/spdlog.h index 65d3e9d5..5bc6f2be 100644 --- a/include/spdlog/spdlog.h +++ b/include/spdlog/spdlog.h @@ -103,6 +103,9 @@ SPDLOG_API void drop_all(); // stop any running threads started by spdlog and clean registry loggers SPDLOG_API void shutdown(); +// get count of lost log +SPDLOG_API size_t overrun_counter(); + // Automatic registration of loggers when using spdlog::create() or spdlog::create_async SPDLOG_API void set_automatic_registration(bool automatic_registration);