[FEAT] add api:overrun_counter

pull/2426/head
izlyforever 3 years ago
parent 6c95f4c816
commit 65eabb60b9

@ -9,6 +9,7 @@
#include <spdlog/common.h> #include <spdlog/common.h>
#include <spdlog/details/periodic_worker.h> #include <spdlog/details/periodic_worker.h>
#include <spdlog/details/thread_pool.h>
#include <spdlog/logger.h> #include <spdlog/logger.h>
#include <spdlog/pattern_formatter.h> #include <spdlog/pattern_formatter.h>
@ -256,6 +257,15 @@ SPDLOG_INLINE void registry::shutdown()
} }
} }
SPDLOG_INLINE size_t registry::overrun_counter()
{
std::lock_guard<std::recursive_mutex> lock(tp_mutex_);
if (!tp_) {
return 0;
}
return tp_->overrun_counter();
}
SPDLOG_INLINE std::recursive_mutex &registry::tp_mutex() SPDLOG_INLINE std::recursive_mutex &registry::tp_mutex()
{ {
return tp_mutex_; return tp_mutex_;

@ -76,6 +76,9 @@ public:
// clean all resources and threads started by the registry // clean all resources and threads started by the registry
void shutdown(); void shutdown();
// get count of lost log
size_t overrun_counter();
std::recursive_mutex &tp_mutex(); std::recursive_mutex &tp_mutex();
void set_automatic_registration(bool automatic_registration); void set_automatic_registration(bool automatic_registration);

@ -7,6 +7,7 @@
# include <spdlog/details/thread_pool.h> # include <spdlog/details/thread_pool.h>
#endif #endif
#include <spdlog/async_logger.h>
#include <spdlog/common.h> #include <spdlog/common.h>
#include <cassert> #include <cassert>

@ -15,6 +15,7 @@
namespace spdlog { namespace spdlog {
class async_logger; class async_logger;
enum class async_overflow_policy;
namespace details { namespace details {

@ -102,6 +102,11 @@ SPDLOG_INLINE void shutdown()
details::registry::instance().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) SPDLOG_INLINE void set_automatic_registration(bool automatic_registration)
{ {
details::registry::instance().set_automatic_registration(automatic_registration); details::registry::instance().set_automatic_registration(automatic_registration);

@ -103,6 +103,9 @@ SPDLOG_API void drop_all();
// stop any running threads started by spdlog and clean registry loggers // stop any running threads started by spdlog and clean registry loggers
SPDLOG_API void shutdown(); 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 // Automatic registration of loggers when using spdlog::create() or spdlog::create_async
SPDLOG_API void set_automatic_registration(bool automatic_registration); SPDLOG_API void set_automatic_registration(bool automatic_registration);

Loading…
Cancel
Save