diff --git a/include/spdlog/common.h b/include/spdlog/common.h index 5bc9a02e..e71007b2 100644 --- a/include/spdlog/common.h +++ b/include/spdlog/common.h @@ -173,9 +173,9 @@ enum class log_level }; #if defined(SPDLOG_NO_ATOMIC_LEVELS) - using level_t = details::null_atomic_log_level; + using atomic_level_t = details::null_atomic; #else - using level_t = std::atomic; + using atomic_level_t = std::atomic; #endif #if !defined(SPDLOG_LEVEL_NAMES) diff --git a/include/spdlog/details/null_mutex.h b/include/spdlog/details/null_mutex.h index cd0ceed0..91b216b6 100644 --- a/include/spdlog/details/null_mutex.h +++ b/include/spdlog/details/null_mutex.h @@ -9,7 +9,6 @@ // null, no cost dummy "mutex" and dummy "atomic" log level namespace spdlog { -enum class log_level; // forward declaration namespace details { struct null_mutex @@ -18,25 +17,26 @@ struct null_mutex void unlock() const {} }; -struct null_atomic_log_level +template +struct null_atomic { - spdlog::log_level value; + T value; - explicit null_atomic_log_level(spdlog::log_level new_value) + explicit null_atomic(T new_value) : value(new_value) {} - [[nodiscard]] log_level load(std::memory_order = std::memory_order_relaxed) const + [[nodiscard]] T load(std::memory_order = std::memory_order_relaxed) const { return value; } - void store(log_level new_value, std::memory_order = std::memory_order_relaxed) + void store(T new_value, std::memory_order = std::memory_order_relaxed) { value = new_value; } - log_level exchange(log_level new_value, std::memory_order = std::memory_order_relaxed) + T exchange(T new_value, std::memory_order = std::memory_order_relaxed) { std::swap(new_value, value); return new_value; // return value before the call diff --git a/include/spdlog/logger.h b/include/spdlog/logger.h index 59b200b5..407d604a 100644 --- a/include/spdlog/logger.h +++ b/include/spdlog/logger.h @@ -310,8 +310,8 @@ public: protected: std::string name_; std::vector sinks_; - spdlog::level_t level_{log_level::info}; - spdlog::level_t flush_level_{log_level::off}; + spdlog::atomic_level_t level_{log_level::info}; + spdlog::atomic_level_t flush_level_{log_level::off}; err_handler custom_err_handler_{nullptr}; // common implementation for after templated public api has been resolved to format string and args diff --git a/include/spdlog/sinks/sink.h b/include/spdlog/sinks/sink.h index 68cd8524..c8d3005c 100644 --- a/include/spdlog/sinks/sink.h +++ b/include/spdlog/sinks/sink.h @@ -24,7 +24,7 @@ public: protected: // sink log level - default is all - level_t level_{log_level::trace}; + atomic_level_t level_{log_level::trace}; }; } // namespace sinks