diff --git a/include/spdlog/async_logger-inl.h b/include/spdlog/async_logger-inl.h index f8c9694c..9a651b71 100644 --- a/include/spdlog/async_logger-inl.h +++ b/include/spdlog/async_logger-inl.h @@ -84,7 +84,7 @@ SPDLOG_INLINE void spdlog::async_logger::backend_flush_() } } -SPDLOG_INLINE std::shared_ptr spdlog::async_logger::clone(std::string new_name) +SPDLOG_INLINE std::shared_ptr spdlog::async_logger::clone(std::string new_name) const& { auto cloned = std::make_shared(*this); cloned->name_ = std::move(new_name); diff --git a/include/spdlog/async_logger.h b/include/spdlog/async_logger.h index 6f299672..ba116d44 100644 --- a/include/spdlog/async_logger.h +++ b/include/spdlog/async_logger.h @@ -49,7 +49,7 @@ public: async_logger(std::string logger_name, sink_ptr single_sink, std::weak_ptr tp, async_overflow_policy overflow_policy = async_overflow_policy::block); - std::shared_ptr clone(std::string new_name) override; + std::shared_ptr clone(std::string new_name) const & override; protected: void sink_it_(const details::log_msg &msg) override; diff --git a/include/spdlog/details/backtracer-inl.h b/include/spdlog/details/backtracer-inl.h index 21553c26..6617b789 100644 --- a/include/spdlog/details/backtracer-inl.h +++ b/include/spdlog/details/backtracer-inl.h @@ -22,7 +22,7 @@ SPDLOG_INLINE backtracer::backtracer(backtracer &&other) SPDLOG_NOEXCEPT messages_ = std::move(other.messages_); } -SPDLOG_INLINE backtracer &backtracer::operator=(backtracer other) +SPDLOG_INLINE backtracer &backtracer::operator=(backtracer other) & { std::lock_guard lock(mutex_); enabled_ = other.enabled(); diff --git a/include/spdlog/details/backtracer.h b/include/spdlog/details/backtracer.h index 81736580..e92cc40c 100644 --- a/include/spdlog/details/backtracer.h +++ b/include/spdlog/details/backtracer.h @@ -26,7 +26,7 @@ public: backtracer(const backtracer &other); backtracer(backtracer &&other) SPDLOG_NOEXCEPT; - backtracer &operator=(backtracer other); + backtracer &operator=(backtracer other) &; void enable(size_t size); void disable(); @@ -43,4 +43,3 @@ public: #ifdef SPDLOG_HEADER_ONLY #include "backtracer-inl.h" #endif - diff --git a/include/spdlog/details/circular_q.h b/include/spdlog/details/circular_q.h index 1f2712e7..0062e6c0 100644 --- a/include/spdlog/details/circular_q.h +++ b/include/spdlog/details/circular_q.h @@ -30,7 +30,7 @@ public: {} circular_q(const circular_q &) = default; - circular_q &operator=(const circular_q &) = default; + circular_q &operator=(const circular_q &) & = default; // move cannot be default, // since we need to reset head_, tail_, etc to zero in the moved object @@ -39,14 +39,14 @@ public: copy_moveable(std::move(other)); } - circular_q &operator=(circular_q &&other) SPDLOG_NOEXCEPT + circular_q &operator=(circular_q &&other) & SPDLOG_NOEXCEPT { copy_moveable(std::move(other)); return *this; } // push back, overrun (oldest) item if no room left - void push_back(T &&item) + void push_back(T &&item) & { if (max_items_ > 0) { @@ -63,16 +63,21 @@ public: // Return reference to the front item. // If there are no elements in the container, the behavior is undefined. - const T &front() const + const T &front() const & { return v_[head_]; } - T &front() + T &front() & { return v_[head_]; } + T front() && + { + return std::move(v_[head_]); + } + // Return number of elements actually stored size_t size() const { @@ -96,7 +101,7 @@ public: // Pop item from front. // If there are no elements in the container, the behavior is undefined. - void pop_front() + void pop_front() & { head_ = (head_ + 1) % max_items_; } diff --git a/include/spdlog/details/log_msg_buffer-inl.h b/include/spdlog/details/log_msg_buffer-inl.h index ca9429bb..a4c9fcd8 100644 --- a/include/spdlog/details/log_msg_buffer-inl.h +++ b/include/spdlog/details/log_msg_buffer-inl.h @@ -26,14 +26,12 @@ SPDLOG_INLINE log_msg_buffer::log_msg_buffer(const log_msg_buffer &other) update_string_views(); } -SPDLOG_INLINE log_msg_buffer::log_msg_buffer(log_msg_buffer &&other) SPDLOG_NOEXCEPT - : log_msg{other} - , buffer{std::move(other.buffer)} +SPDLOG_INLINE log_msg_buffer::log_msg_buffer(log_msg_buffer &&other) SPDLOG_NOEXCEPT : log_msg{other}, buffer{std::move(other.buffer)} { update_string_views(); } -SPDLOG_INLINE log_msg_buffer &log_msg_buffer::operator=(const log_msg_buffer &other) +SPDLOG_INLINE log_msg_buffer &log_msg_buffer::operator=(const log_msg_buffer &other) & { log_msg::operator=(other); buffer.clear(); @@ -42,7 +40,7 @@ SPDLOG_INLINE log_msg_buffer &log_msg_buffer::operator=(const log_msg_buffer &ot return *this; } -SPDLOG_INLINE log_msg_buffer &log_msg_buffer::operator=(log_msg_buffer &&other) SPDLOG_NOEXCEPT +SPDLOG_INLINE log_msg_buffer &log_msg_buffer::operator=(log_msg_buffer &&other) & SPDLOG_NOEXCEPT { log_msg::operator=(other); buffer = std::move(other.buffer); diff --git a/include/spdlog/details/log_msg_buffer.h b/include/spdlog/details/log_msg_buffer.h index 4410110f..db35f40e 100644 --- a/include/spdlog/details/log_msg_buffer.h +++ b/include/spdlog/details/log_msg_buffer.h @@ -21,8 +21,8 @@ public: explicit log_msg_buffer(const log_msg &orig_msg); log_msg_buffer(const log_msg_buffer &other); log_msg_buffer(log_msg_buffer &&other) SPDLOG_NOEXCEPT; - log_msg_buffer &operator=(const log_msg_buffer &other); - log_msg_buffer &operator=(log_msg_buffer &&other) SPDLOG_NOEXCEPT; + log_msg_buffer &operator=(const log_msg_buffer &other) &; + log_msg_buffer &operator=(log_msg_buffer &&other) & SPDLOG_NOEXCEPT; }; } // namespace details diff --git a/include/spdlog/details/mpmc_blocking_q.h b/include/spdlog/details/mpmc_blocking_q.h index 5c3cca76..3202d12e 100644 --- a/include/spdlog/details/mpmc_blocking_q.h +++ b/include/spdlog/details/mpmc_blocking_q.h @@ -29,7 +29,7 @@ public: #ifndef __MINGW32__ // try to enqueue and block if no room left - void enqueue(T &&item) + void enqueue(T &&item) & { { std::unique_lock lock(queue_mutex_); @@ -40,7 +40,7 @@ public: } // enqueue immediately. overrun oldest message in the queue if no room left. - void enqueue_nowait(T &&item) + void enqueue_nowait(T &&item) & { { std::unique_lock lock(queue_mutex_); @@ -71,7 +71,7 @@ public: // so release the mutex at the very end each function. // try to enqueue and block if no room left - void enqueue(T &&item) + void enqueue(T &&item) & { std::unique_lock lock(queue_mutex_); pop_cv_.wait(lock, [this] { return !this->q_.full(); }); @@ -80,7 +80,7 @@ public: } // enqueue immediately. overrun oldest message in the queue if no room left. - void enqueue_nowait(T &&item) + void enqueue_nowait(T &&item) & { std::unique_lock lock(queue_mutex_); q_.push_back(std::move(item)); @@ -104,20 +104,20 @@ public: #endif - size_t overrun_counter() + size_t overrun_counter() const { std::unique_lock lock(queue_mutex_); return q_.overrun_counter(); } - size_t size() + size_t size() const { std::unique_lock lock(queue_mutex_); return q_.size(); } private: - std::mutex queue_mutex_; + mutable std::mutex queue_mutex_; std::condition_variable push_cv_; std::condition_variable pop_cv_; spdlog::details::circular_q q_; diff --git a/include/spdlog/details/registry-inl.h b/include/spdlog/details/registry-inl.h index a60faabc..e677f44c 100644 --- a/include/spdlog/details/registry-inl.h +++ b/include/spdlog/details/registry-inl.h @@ -51,13 +51,13 @@ SPDLOG_INLINE registry::registry() SPDLOG_INLINE registry::~registry() = default; -SPDLOG_INLINE void registry::register_logger(std::shared_ptr new_logger) +SPDLOG_INLINE void registry::register_logger(std::shared_ptr new_logger) & { std::lock_guard lock(logger_map_mutex_); register_logger_(std::move(new_logger)); } -SPDLOG_INLINE void registry::initialize_logger(std::shared_ptr new_logger) +SPDLOG_INLINE void registry::initialize_logger(std::shared_ptr new_logger) & { std::lock_guard lock(logger_map_mutex_); new_logger->set_formatter(formatter_->clone()); @@ -109,7 +109,7 @@ SPDLOG_INLINE logger *registry::get_default_raw() // set default logger. // default logger is stored in default_logger_ (for faster retrieval) and in the loggers_ map. -SPDLOG_INLINE void registry::set_default_logger(std::shared_ptr new_default_logger) +SPDLOG_INLINE void registry::set_default_logger(std::shared_ptr new_default_logger) & { std::lock_guard lock(logger_map_mutex_); // remove previous default logger from the map @@ -124,7 +124,7 @@ SPDLOG_INLINE void registry::set_default_logger(std::shared_ptr new_defa default_logger_ = std::move(new_default_logger); } -SPDLOG_INLINE void registry::set_tp(std::shared_ptr tp) +SPDLOG_INLINE void registry::set_tp(std::shared_ptr tp) & { std::lock_guard lock(tp_mutex_); tp_ = std::move(tp); @@ -137,7 +137,7 @@ SPDLOG_INLINE std::shared_ptr registry::get_tp() } // Set global formatter. Each sink in each logger will get a clone of this object -SPDLOG_INLINE void registry::set_formatter(std::unique_ptr formatter) +SPDLOG_INLINE void registry::set_formatter(std::unique_ptr formatter) & { std::lock_guard lock(logger_map_mutex_); formatter_ = std::move(formatter); @@ -147,7 +147,7 @@ SPDLOG_INLINE void registry::set_formatter(std::unique_ptr formatter) } } -SPDLOG_INLINE void registry::enable_backtrace(size_t n_messages) +SPDLOG_INLINE void registry::enable_backtrace(size_t n_messages) & { std::lock_guard lock(logger_map_mutex_); backtrace_n_messages_ = n_messages; @@ -158,7 +158,7 @@ SPDLOG_INLINE void registry::enable_backtrace(size_t n_messages) } } -SPDLOG_INLINE void registry::disable_backtrace() +SPDLOG_INLINE void registry::disable_backtrace() & { std::lock_guard lock(logger_map_mutex_); backtrace_n_messages_ = 0; @@ -168,7 +168,7 @@ SPDLOG_INLINE void registry::disable_backtrace() } } -SPDLOG_INLINE void registry::set_level(level::level_enum log_level) +SPDLOG_INLINE void registry::set_level(level::level_enum log_level) & { std::lock_guard lock(logger_map_mutex_); for (auto &l : loggers_) @@ -178,7 +178,7 @@ SPDLOG_INLINE void registry::set_level(level::level_enum log_level) global_log_level_ = log_level; } -SPDLOG_INLINE void registry::flush_on(level::level_enum log_level) +SPDLOG_INLINE void registry::flush_on(level::level_enum log_level) & { std::lock_guard lock(logger_map_mutex_); for (auto &l : loggers_) @@ -188,14 +188,14 @@ SPDLOG_INLINE void registry::flush_on(level::level_enum log_level) flush_level_ = log_level; } -SPDLOG_INLINE void registry::flush_every(std::chrono::seconds interval) +SPDLOG_INLINE void registry::flush_every(std::chrono::seconds interval) & { std::lock_guard lock(flusher_mutex_); auto clbk = [this]() { this->flush_all(); }; periodic_flusher_ = details::make_unique(clbk, interval); } -SPDLOG_INLINE void registry::set_error_handler(void (*handler)(const std::string &msg)) +SPDLOG_INLINE void registry::set_error_handler(void (*handler)(const std::string &msg)) & { std::lock_guard lock(logger_map_mutex_); for (auto &l : loggers_) @@ -261,13 +261,13 @@ SPDLOG_INLINE std::recursive_mutex ®istry::tp_mutex() return tp_mutex_; } -SPDLOG_INLINE void registry::set_automatic_registration(bool automatic_registration) +SPDLOG_INLINE void registry::set_automatic_registration(bool automatic_registration) & { std::lock_guard lock(logger_map_mutex_); automatic_registration_ = automatic_registration; } -SPDLOG_INLINE void registry::set_levels(log_levels levels, level::level_enum *global_level) +SPDLOG_INLINE void registry::set_levels(log_levels levels, level::level_enum *global_level) & { std::lock_guard lock(logger_map_mutex_); log_levels_ = std::move(levels); @@ -302,7 +302,7 @@ SPDLOG_INLINE void registry::throw_if_exists_(const std::string &logger_name) } } -SPDLOG_INLINE void registry::register_logger_(std::shared_ptr new_logger) +SPDLOG_INLINE void registry::register_logger_(std::shared_ptr new_logger) & { auto logger_name = new_logger->name(); throw_if_exists_(logger_name); diff --git a/include/spdlog/details/registry.h b/include/spdlog/details/registry.h index b069c3f5..67660d53 100644 --- a/include/spdlog/details/registry.h +++ b/include/spdlog/details/registry.h @@ -31,8 +31,8 @@ public: registry(const registry &) = delete; registry &operator=(const registry &) = delete; - void register_logger(std::shared_ptr new_logger); - void initialize_logger(std::shared_ptr new_logger); + void register_logger(std::shared_ptr new_logger) &; + void initialize_logger(std::shared_ptr new_logger) &; std::shared_ptr get(const std::string &logger_name); std::shared_ptr default_logger(); @@ -44,26 +44,26 @@ public: // set default logger. // default logger is stored in default_logger_ (for faster retrieval) and in the loggers_ map. - void set_default_logger(std::shared_ptr new_default_logger); + void set_default_logger(std::shared_ptr new_default_logger) &; - void set_tp(std::shared_ptr tp); + void set_tp(std::shared_ptr tp) &; std::shared_ptr get_tp(); // Set global formatter. Each sink in each logger will get a clone of this object - void set_formatter(std::unique_ptr formatter); + void set_formatter(std::unique_ptr formatter) &; - void enable_backtrace(size_t n_messages); + void enable_backtrace(size_t n_messages) &; - void disable_backtrace(); + void disable_backtrace() &; - void set_level(level::level_enum log_level); + void set_level(level::level_enum log_level) &; - void flush_on(level::level_enum log_level); + void flush_on(level::level_enum log_level) &; - void flush_every(std::chrono::seconds interval); + void flush_every(std::chrono::seconds interval) &; - void set_error_handler(void (*handler)(const std::string &msg)); + void set_error_handler(void (*handler)(const std::string &msg)) &; void apply_all(const std::function)> &fun); @@ -78,10 +78,10 @@ public: std::recursive_mutex &tp_mutex(); - void set_automatic_registration(bool automatic_registration); + void set_automatic_registration(bool automatic_registration) &; // set levels for all existing/future loggers. global_level can be null if should not set. - void set_levels(log_levels levels, level::level_enum *global_level); + void set_levels(log_levels levels, level::level_enum *global_level) &; static registry &instance(); @@ -90,8 +90,9 @@ private: ~registry(); void throw_if_exists_(const std::string &logger_name); - void register_logger_(std::shared_ptr new_logger); + void register_logger_(std::shared_ptr new_logger) &; bool set_level_from_cfg_(logger *logger); + std::mutex logger_map_mutex_, flusher_mutex_; std::recursive_mutex tp_mutex_; std::unordered_map> loggers_; diff --git a/include/spdlog/details/tcp_client-windows.h b/include/spdlog/details/tcp_client-windows.h index 7ee72927..88bc0e52 100644 --- a/include/spdlog/details/tcp_client-windows.h +++ b/include/spdlog/details/tcp_client-windows.h @@ -64,7 +64,7 @@ public: return socket_ != INVALID_SOCKET; } - void close() + void close() & { ::closesocket(socket_); socket_ = INVALID_SOCKET; @@ -82,7 +82,7 @@ public: } // try to connect or throw on failure - void connect(const std::string &host, int port) + void connect(const std::string &host, int port) & { // initialize winsock if needed if (!winsock_initialized_()) diff --git a/include/spdlog/details/tcp_client.h b/include/spdlog/details/tcp_client.h index 9f3bb99e..2790848b 100644 --- a/include/spdlog/details/tcp_client.h +++ b/include/spdlog/details/tcp_client.h @@ -31,7 +31,7 @@ public: return socket_ != -1; } - void close() + void close() & { if (is_connected()) { @@ -51,7 +51,7 @@ public: } // try to connect or throw on failure - void connect(const std::string &host, int port) + void connect(const std::string &host, int port) & { close(); struct addrinfo hints diff --git a/include/spdlog/details/thread_pool-inl.h b/include/spdlog/details/thread_pool-inl.h index c1df4361..394335ea 100644 --- a/include/spdlog/details/thread_pool-inl.h +++ b/include/spdlog/details/thread_pool-inl.h @@ -63,17 +63,17 @@ void SPDLOG_INLINE thread_pool::post_flush(async_logger_ptr &&worker_ptr, async_ post_async_msg_(async_msg(std::move(worker_ptr), async_msg_type::flush), overflow_policy); } -size_t SPDLOG_INLINE thread_pool::overrun_counter() +size_t SPDLOG_INLINE thread_pool::overrun_counter() const { return q_.overrun_counter(); } -size_t SPDLOG_INLINE thread_pool::queue_size() +size_t SPDLOG_INLINE thread_pool::queue_size() const { return q_.size(); } -void SPDLOG_INLINE thread_pool::post_async_msg_(async_msg &&new_msg, async_overflow_policy overflow_policy) +void SPDLOG_INLINE thread_pool::post_async_msg_(async_msg &&new_msg, async_overflow_policy overflow_policy) & { if (overflow_policy == async_overflow_policy::block) { @@ -85,7 +85,7 @@ void SPDLOG_INLINE thread_pool::post_async_msg_(async_msg &&new_msg, async_overf } } -void SPDLOG_INLINE thread_pool::worker_loop_() +void SPDLOG_INLINE thread_pool::worker_loop_() & { while (process_next_msg_()) {} } @@ -93,7 +93,7 @@ void SPDLOG_INLINE thread_pool::worker_loop_() // process next message in the queue // return true if this thread should still be active (while no terminate msg // was received) -bool SPDLOG_INLINE thread_pool::process_next_msg_() +bool SPDLOG_INLINE thread_pool::process_next_msg_() & { async_msg incoming_async_msg; bool dequeued = q_.dequeue_for(incoming_async_msg, std::chrono::seconds(10)); diff --git a/include/spdlog/details/thread_pool.h b/include/spdlog/details/thread_pool.h index 61e25252..53910257 100644 --- a/include/spdlog/details/thread_pool.h +++ b/include/spdlog/details/thread_pool.h @@ -49,7 +49,7 @@ struct async_msg : log_msg_buffer , worker_ptr(std::move(other.worker_ptr)) {} - async_msg &operator=(async_msg &&other) + async_msg &operator=(async_msg &&other) & { *static_cast(this) = std::move(other); msg_type = other.msg_type; @@ -58,7 +58,7 @@ struct async_msg : log_msg_buffer } #else // (_MSC_VER) && _MSC_VER <= 1800 async_msg(async_msg &&) = default; - async_msg &operator=(async_msg &&) = default; + async_msg &operator=(async_msg &&) & = default; #endif // construct from log_msg with given type @@ -96,21 +96,21 @@ public: void post_log(async_logger_ptr &&worker_ptr, const details::log_msg &msg, async_overflow_policy overflow_policy); void post_flush(async_logger_ptr &&worker_ptr, async_overflow_policy overflow_policy); - size_t overrun_counter(); - size_t queue_size(); + size_t overrun_counter() const; + size_t queue_size() const; private: q_type q_; std::vector threads_; - void post_async_msg_(async_msg &&new_msg, async_overflow_policy overflow_policy); - void worker_loop_(); + void post_async_msg_(async_msg &&new_msg, async_overflow_policy overflow_policy) &; + void worker_loop_() &; // process next message in the queue // return true if this thread should still be active (while no terminate msg // was received) - bool process_next_msg_(); + bool process_next_msg_() &; }; } // namespace details diff --git a/include/spdlog/logger-inl.h b/include/spdlog/logger-inl.h index d01c08da..a39e2c83 100644 --- a/include/spdlog/logger-inl.h +++ b/include/spdlog/logger-inl.h @@ -34,13 +34,13 @@ SPDLOG_INLINE logger::logger(logger &&other) SPDLOG_NOEXCEPT : name_(std::move(o {} -SPDLOG_INLINE logger &logger::operator=(logger other) SPDLOG_NOEXCEPT +SPDLOG_INLINE logger &logger::operator=(logger other) & SPDLOG_NOEXCEPT { this->swap(other); return *this; } -SPDLOG_INLINE void logger::swap(spdlog::logger &other) SPDLOG_NOEXCEPT +SPDLOG_INLINE void logger::swap(spdlog::logger &other) & SPDLOG_NOEXCEPT { name_.swap(other.name_); sinks_.swap(other.sinks_); @@ -64,7 +64,7 @@ SPDLOG_INLINE void swap(logger &a, logger &b) a.swap(b); } -SPDLOG_INLINE void logger::set_level(level::level_enum log_level) +SPDLOG_INLINE void logger::set_level(level::level_enum log_level) & { level_.store(log_level); } @@ -74,14 +74,24 @@ SPDLOG_INLINE level::level_enum logger::level() const return static_cast(level_.load(std::memory_order_relaxed)); } -SPDLOG_INLINE const std::string &logger::name() const +SPDLOG_INLINE std::string logger::name() && +{ + return std::move(name_); +} + +SPDLOG_INLINE const std::string &logger::name() const & +{ + return name_; +} + +SPDLOG_INLINE std::string &logger::name() & { return name_; } // set formatting for the sinks in this logger. // each sink will get a separate instance of the formatter object. -SPDLOG_INLINE void logger::set_formatter(std::unique_ptr f) +SPDLOG_INLINE void logger::set_formatter(std::unique_ptr f) & { for (auto it = sinks_.begin(); it != sinks_.end(); ++it) { @@ -98,20 +108,20 @@ SPDLOG_INLINE void logger::set_formatter(std::unique_ptr f) } } -SPDLOG_INLINE void logger::set_pattern(std::string pattern, pattern_time_type time_type) +SPDLOG_INLINE void logger::set_pattern(std::string pattern, pattern_time_type time_type) & { auto new_formatter = details::make_unique(std::move(pattern), time_type); set_formatter(std::move(new_formatter)); } // create new backtrace sink and move to it all our child sinks -SPDLOG_INLINE void logger::enable_backtrace(size_t n_messages) +SPDLOG_INLINE void logger::enable_backtrace(size_t n_messages) & { tracer_.enable(n_messages); } // restore orig sinks and level and delete the backtrace sink -SPDLOG_INLINE void logger::disable_backtrace() +SPDLOG_INLINE void logger::disable_backtrace() & { tracer_.disable(); } @@ -138,24 +148,29 @@ SPDLOG_INLINE level::level_enum logger::flush_level() const } // sinks -SPDLOG_INLINE const std::vector &logger::sinks() const +SPDLOG_INLINE std::vector logger::sinks() && +{ + return std::move(sinks_); +} + +SPDLOG_INLINE const std::vector &logger::sinks() const & { return sinks_; } -SPDLOG_INLINE std::vector &logger::sinks() +SPDLOG_INLINE std::vector &logger::sinks() & { return sinks_; } // error handler -SPDLOG_INLINE void logger::set_error_handler(err_handler handler) +SPDLOG_INLINE void logger::set_error_handler(err_handler handler) & { custom_err_handler_ = std::move(handler); } // create new logger with same sinks and configuration. -SPDLOG_INLINE std::shared_ptr logger::clone(std::string logger_name) +SPDLOG_INLINE std::shared_ptr logger::clone(std::string logger_name) const & { auto cloned = std::make_shared(*this); cloned->name_ = std::move(logger_name); diff --git a/include/spdlog/logger.h b/include/spdlog/logger.h index a34c5221..ae608104 100644 --- a/include/spdlog/logger.h +++ b/include/spdlog/logger.h @@ -69,62 +69,62 @@ public: logger(const logger &other); logger(logger &&other) SPDLOG_NOEXCEPT; - logger &operator=(logger other) SPDLOG_NOEXCEPT; + logger &operator=(logger other) & SPDLOG_NOEXCEPT; - void swap(spdlog::logger &other) SPDLOG_NOEXCEPT; + void swap(spdlog::logger &other) & SPDLOG_NOEXCEPT; // FormatString is a type derived from fmt::compile_string template::value, int>::type = 0, typename... Args> - void log(source_loc loc, level::level_enum lvl, const FormatString &fmt, Args&&...args) + void log(source_loc loc, level::level_enum lvl, const FormatString &fmt, Args &&...args) { log_(loc, lvl, fmt, std::forward(args)...); } // FormatString is NOT a type derived from fmt::compile_string but is a string_view_t or can be implicitly converted to one template - void log(source_loc loc, level::level_enum lvl, string_view_t fmt, Args&&...args) + void log(source_loc loc, level::level_enum lvl, string_view_t fmt, Args &&...args) { log_(loc, lvl, fmt, std::forward(args)...); } template - void log(level::level_enum lvl, const FormatString &fmt, Args&&...args) + void log(level::level_enum lvl, const FormatString &fmt, Args &&...args) { log(source_loc{}, lvl, fmt, std::forward(args)...); } template - void trace(const FormatString &fmt, Args&&...args) + void trace(const FormatString &fmt, Args &&...args) { log(level::trace, fmt, std::forward(args)...); } template - void debug(const FormatString &fmt, Args&&...args) + void debug(const FormatString &fmt, Args &&...args) { log(level::debug, fmt, std::forward(args)...); } template - void info(const FormatString &fmt, Args&&...args) + void info(const FormatString &fmt, Args &&...args) { log(level::info, fmt, std::forward(args)...); } template - void warn(const FormatString &fmt, Args&&...args) + void warn(const FormatString &fmt, Args &&...args) { log(level::warn, fmt, std::forward(args)...); } template - void error(const FormatString &fmt, Args&&...args) + void error(const FormatString &fmt, Args &&...args) { log(level::err, fmt, std::forward(args)...); } template - void critical(const FormatString &fmt, Args&&...args) + void critical(const FormatString &fmt, Args &&...args) { log(level::critical, fmt, std::forward(args)...); } @@ -225,7 +225,7 @@ public: #else template - void log(source_loc loc, level::level_enum lvl, wstring_view_t fmt, Args&&...args) + void log(source_loc loc, level::level_enum lvl, wstring_view_t fmt, Args &&...args) { bool log_enabled = should_log(lvl); bool traceback_enabled = tracer_.enabled(); @@ -282,22 +282,24 @@ public: return tracer_.enabled(); } - void set_level(level::level_enum log_level); + void set_level(level::level_enum log_level) &; level::level_enum level() const; - const std::string &name() const; + std::string name() &&; + const std::string &name() const&; + std::string &name() &; // set formatting for the sinks in this logger. // each sink will get a separate instance of the formatter object. - void set_formatter(std::unique_ptr f); + void set_formatter(std::unique_ptr f) &; - void set_pattern(std::string pattern, pattern_time_type time_type = pattern_time_type::local); + void set_pattern(std::string pattern, pattern_time_type time_type = pattern_time_type::local) &; // backtrace support. // efficiently store all debug/trace messages in a circular buffer until needed for debugging. - void enable_backtrace(size_t n_messages); - void disable_backtrace(); + void enable_backtrace(size_t n_messages) &; + void disable_backtrace() &; void dump_backtrace(); // flush functions @@ -306,15 +308,15 @@ public: level::level_enum flush_level() const; // sinks - const std::vector &sinks() const; - - std::vector &sinks(); + std::vector sinks() &&; + const std::vector &sinks() const &; + std::vector &sinks() &; // error handler - void set_error_handler(err_handler); + void set_error_handler(err_handler) &; // create new logger with same sinks and configuration. - virtual std::shared_ptr clone(std::string logger_name); + virtual std::shared_ptr clone(std::string logger_name) const&; protected: std::string name_; @@ -326,7 +328,7 @@ protected: // common implementation for after templated public api has been resolved template - void log_(source_loc loc, level::level_enum lvl, const FormatString &fmt, Args&&...args) + void log_(source_loc loc, level::level_enum lvl, const FormatString &fmt, Args &&...args) { bool log_enabled = should_log(lvl); bool traceback_enabled = tracer_.enabled(); diff --git a/include/spdlog/pattern_formatter-inl.h b/include/spdlog/pattern_formatter-inl.h index c6cd5e83..c324299d 100644 --- a/include/spdlog/pattern_formatter-inl.h +++ b/include/spdlog/pattern_formatter-inl.h @@ -1064,7 +1064,7 @@ SPDLOG_INLINE void pattern_formatter::format(const details::log_msg &msg, memory details::fmt_helper::append_string_view(eol_, dest); } -SPDLOG_INLINE void pattern_formatter::set_pattern(std::string pattern) +SPDLOG_INLINE void pattern_formatter::set_pattern(std::string pattern) & { pattern_ = std::move(pattern); compile_pattern_(pattern_); diff --git a/include/spdlog/pattern_formatter.h b/include/spdlog/pattern_formatter.h index bc13ae10..4a483393 100644 --- a/include/spdlog/pattern_formatter.h +++ b/include/spdlog/pattern_formatter.h @@ -68,7 +68,7 @@ class SPDLOG_API custom_flag_formatter : public details::flag_formatter public: virtual std::unique_ptr clone() const = 0; - void set_padding_info(details::padding_info padding) + void set_padding_info(details::padding_info padding) & { flag_formatter::padinfo_ = padding; } @@ -92,12 +92,12 @@ public: void format(const details::log_msg &msg, memory_buf_t &dest) override; template - pattern_formatter &add_flag(char flag, Args&&...args) + pattern_formatter &add_flag(char flag, Args&&...args) & { custom_handlers_[flag] = details::make_unique(std::forward(args)...); return *this; } - void set_pattern(std::string pattern); + void set_pattern(std::string pattern) &; private: std::string pattern_; diff --git a/include/spdlog/stopwatch.h b/include/spdlog/stopwatch.h index bb976b19..af77b34e 100644 --- a/include/spdlog/stopwatch.h +++ b/include/spdlog/stopwatch.h @@ -40,7 +40,7 @@ public: return std::chrono::duration(clock::now() - start_tp_); } - void reset() + void reset() & { start_tp_ = clock ::now(); }