From 89afa909e14344ec486b1435b8e62ba6000d4406 Mon Sep 17 00:00:00 2001 From: gabime Date: Thu, 15 Jan 2015 10:34:50 +0200 Subject: [PATCH] shortened enum policy name and moved into common.h --- include/spdlog/async_logger.h | 6 +++--- include/spdlog/common.h | 11 +++++++++++ include/spdlog/details/async_log_helper.h | 8 ++++---- include/spdlog/details/async_logger_impl.h | 6 +++--- include/spdlog/details/registry.h | 4 ++-- include/spdlog/details/spdlog_impl.h | 2 +- include/spdlog/spdlog.h | 13 +------------ 7 files changed, 25 insertions(+), 25 deletions(-) diff --git a/include/spdlog/async_logger.h b/include/spdlog/async_logger.h index 94a0d100..5ff53108 100644 --- a/include/spdlog/async_logger.h +++ b/include/spdlog/async_logger.h @@ -53,9 +53,9 @@ class async_logger :public logger { public: template - async_logger(const std::string& name, const It& begin, const It& end, size_t queue_size, const async_queue_overflow_policy overflow_policy = async_queue_overflow_policy::block_retry, const std::function& worker_warmup_cb = nullptr); - async_logger(const std::string& logger_name, sinks_init_list sinks, size_t queue_size, const async_queue_overflow_policy overflow_policy = async_queue_overflow_policy::block_retry, const std::function& worker_warmup_cb = nullptr); - async_logger(const std::string& logger_name, sink_ptr single_sink, size_t queue_size, const async_queue_overflow_policy overflow_policy = async_queue_overflow_policy::block_retry, const std::function& worker_warmup_cb = nullptr); + async_logger(const std::string& name, const It& begin, const It& end, size_t queue_size, const async_overflow_policy overflow_policy = async_overflow_policy::block_retry, const std::function& worker_warmup_cb = nullptr); + async_logger(const std::string& logger_name, sinks_init_list sinks, size_t queue_size, const async_overflow_policy overflow_policy = async_overflow_policy::block_retry, const std::function& worker_warmup_cb = nullptr); + async_logger(const std::string& logger_name, sink_ptr single_sink, size_t queue_size, const async_overflow_policy overflow_policy = async_overflow_policy::block_retry, const std::function& worker_warmup_cb = nullptr); protected: diff --git a/include/spdlog/common.h b/include/spdlog/common.h index 4d847736..3408bcb9 100644 --- a/include/spdlog/common.h +++ b/include/spdlog/common.h @@ -75,6 +75,17 @@ inline const char* to_str(spdlog::level::level_enum l) } } //level + +// +// Async mode - off by default. +// +enum class async_overflow_policy +{ + block_retry, // Block / yield / sleep until message can be enqueued + discard_log_msg // Discard the message it enqueue fails +}; + + // // Log exception // diff --git a/include/spdlog/details/async_log_helper.h b/include/spdlog/details/async_log_helper.h index 090d5d0a..a77543fa 100644 --- a/include/spdlog/details/async_log_helper.h +++ b/include/spdlog/details/async_log_helper.h @@ -112,7 +112,7 @@ public: async_log_helper(formatter_ptr formatter, const std::vector& sinks, size_t queue_size, - const async_queue_overflow_policy overflow_policy = async_queue_overflow_policy::block_retry, + const async_overflow_policy overflow_policy = async_overflow_policy::block_retry, const std::function& worker_warmup_cb = nullptr); void log(const details::log_msg& msg); @@ -133,7 +133,7 @@ private: std::shared_ptr _last_workerthread_ex; // overflow policy - const async_queue_overflow_policy _overflow_policy; + const async_overflow_policy _overflow_policy; // worker thread warmup callback - one can set thread priority, affinity, etc const std::function _worker_warmup_cb; @@ -161,7 +161,7 @@ private: /////////////////////////////////////////////////////////////////////////////// // async_sink class implementation /////////////////////////////////////////////////////////////////////////////// -inline spdlog::details::async_log_helper::async_log_helper(formatter_ptr formatter, const std::vector& sinks, size_t queue_size, const async_queue_overflow_policy overflow_policy, const std::function& worker_warmup_cb): +inline spdlog::details::async_log_helper::async_log_helper(formatter_ptr formatter, const std::vector& sinks, size_t queue_size, const async_overflow_policy overflow_policy, const std::function& worker_warmup_cb): _formatter(formatter), _sinks(sinks), _q(queue_size), @@ -190,7 +190,7 @@ inline void spdlog::details::async_log_helper::log(const details::log_msg& msg) { throw_if_bad_worker(); async_msg new_msg(msg); - if (!_q.enqueue(std::move(new_msg)) && _overflow_policy != async_queue_overflow_policy::discard_log_msg) + if (!_q.enqueue(std::move(new_msg)) && _overflow_policy != async_overflow_policy::discard_log_msg) { auto last_op_time = clock::now(); do diff --git a/include/spdlog/details/async_logger_impl.h b/include/spdlog/details/async_logger_impl.h index ad84c76a..a4724b90 100644 --- a/include/spdlog/details/async_logger_impl.h +++ b/include/spdlog/details/async_logger_impl.h @@ -34,16 +34,16 @@ template -inline spdlog::async_logger::async_logger(const std::string& logger_name, const It& begin, const It& end, size_t queue_size, const async_queue_overflow_policy overflow_policy, const std::function& worker_warmup_cb) : +inline spdlog::async_logger::async_logger(const std::string& logger_name, const It& begin, const It& end, size_t queue_size, const async_overflow_policy overflow_policy, const std::function& worker_warmup_cb) : logger(logger_name, begin, end), _async_log_helper(new details::async_log_helper(_formatter, _sinks, queue_size, overflow_policy, worker_warmup_cb)) { } -inline spdlog::async_logger::async_logger(const std::string& logger_name, sinks_init_list sinks, size_t queue_size, const async_queue_overflow_policy overflow_policy, const std::function& worker_warmup_cb) : +inline spdlog::async_logger::async_logger(const std::string& logger_name, sinks_init_list sinks, size_t queue_size, const async_overflow_policy overflow_policy, const std::function& worker_warmup_cb) : async_logger(logger_name, sinks.begin(), sinks.end(), queue_size, overflow_policy, worker_warmup_cb) {} -inline spdlog::async_logger::async_logger(const std::string& logger_name, sink_ptr single_sink, size_t queue_size, const async_queue_overflow_policy overflow_policy, const std::function& worker_warmup_cb) : +inline spdlog::async_logger::async_logger(const std::string& logger_name, sink_ptr single_sink, size_t queue_size, const async_overflow_policy overflow_policy, const std::function& worker_warmup_cb) : async_logger(logger_name, { single_sink }, queue_size, overflow_policy, worker_warmup_cb) {} diff --git a/include/spdlog/details/registry.h b/include/spdlog/details/registry.h index d85b5bf5..2d1c2339 100644 --- a/include/spdlog/details/registry.h +++ b/include/spdlog/details/registry.h @@ -120,7 +120,7 @@ public: l.second->set_level(log_level); } - void set_async_mode(size_t q_size, const async_queue_overflow_policy overflow_policy, const std::function& worker_warmup_cb) + void set_async_mode(size_t q_size, const async_overflow_policy overflow_policy, const std::function& worker_warmup_cb) { std::lock_guard lock(_mutex); _async_mode = true; @@ -152,7 +152,7 @@ private: level::level_enum _level = level::info; bool _async_mode = false; size_t _async_q_size = 0; - async_queue_overflow_policy _overflow_policy = async_queue_overflow_policy::block_retry; + async_overflow_policy _overflow_policy = async_overflow_policy::block_retry; std::function _worker_warmup_cb = nullptr; }; } diff --git a/include/spdlog/details/spdlog_impl.h b/include/spdlog/details/spdlog_impl.h index 3dddecd2..69fb85d8 100644 --- a/include/spdlog/details/spdlog_impl.h +++ b/include/spdlog/details/spdlog_impl.h @@ -132,7 +132,7 @@ inline void spdlog::set_level(level::level_enum log_level) } -inline void spdlog::set_async_mode(size_t queue_size, const async_queue_overflow_policy overflow_policy, const std::function& worker_warmup_cb) +inline void spdlog::set_async_mode(size_t queue_size, const async_overflow_policy overflow_policy, const std::function& worker_warmup_cb) { details::registry::instance().set_async_mode(queue_size, overflow_policy, worker_warmup_cb); } diff --git a/include/spdlog/spdlog.h b/include/spdlog/spdlog.h index 27673310..57223eec 100644 --- a/include/spdlog/spdlog.h +++ b/include/spdlog/spdlog.h @@ -57,19 +57,8 @@ void set_formatter(formatter_ptr f); void set_level(level::level_enum log_level); -// -// Async mode - off by default. -// - -enum class async_queue_overflow_policy -{ - block_retry, // Block / yield / sleep until message can be enqueued - discard_log_msg // Discard the message it enqueue fails -}; - // Turn on async mode and set the queue size for each async_logger - -void set_async_mode(size_t queue_size, const async_queue_overflow_policy overflow_policy = async_queue_overflow_policy::block_retry, const std::function& worker_warmup_cb = nullptr); +void set_async_mode(size_t queue_size, const async_overflow_policy overflow_policy = async_overflow_policy::block_retry, const std::function& worker_warmup_cb = nullptr); // Turn off async mode void set_sync_mode();