From 0e5cd15f1ceb7e7c028b78e36fed8d23db66c2a0 Mon Sep 17 00:00:00 2001 From: Dan Cohen Date: Mon, 12 Feb 2024 11:08:05 +0200 Subject: [PATCH] Expose the flusher thread object to user in order to allow setting of thread name and thread affinity when needed --- include/spdlog/details/periodic_worker.h | 1 + include/spdlog/details/registry.h | 2 ++ include/spdlog/spdlog-inl.h | 5 +++++ 3 files changed, 8 insertions(+) diff --git a/include/spdlog/details/periodic_worker.h b/include/spdlog/details/periodic_worker.h index d05245cb..ccac6ff2 100644 --- a/include/spdlog/details/periodic_worker.h +++ b/include/spdlog/details/periodic_worker.h @@ -38,6 +38,7 @@ public: } }); } + std::thread *get_thread() { return &worker_thread_; } periodic_worker(const periodic_worker &) = delete; periodic_worker &operator=(const periodic_worker &) = delete; // stop the worker thread and join it diff --git a/include/spdlog/details/registry.h b/include/spdlog/details/registry.h index 56a6886e..feb6d4f3 100644 --- a/include/spdlog/details/registry.h +++ b/include/spdlog/details/registry.h @@ -68,6 +68,8 @@ public: periodic_flusher_ = details::make_unique(clbk, interval); } + std::unique_ptr &get_flusher() { return periodic_flusher_; } + void set_error_handler(err_handler handler); void apply_all(const std::function)> &fun); diff --git a/include/spdlog/spdlog-inl.h b/include/spdlog/spdlog-inl.h index 97c36222..fac47986 100644 --- a/include/spdlog/spdlog-inl.h +++ b/include/spdlog/spdlog-inl.h @@ -89,4 +89,9 @@ SPDLOG_INLINE void apply_logger_env_levels(std::shared_ptr logger) { details::registry::instance().apply_logger_env_levels(std::move(logger)); } +SPDLOG_INLINE std::unique_ptr &get_flusher() +{ + return details::registry::instance().get_flusher(); +} + } // namespace spdlog