diff --git a/include/spdlog/details/async_log_helper.h b/include/spdlog/details/async_log_helper.h index 179a3db6..2439df5f 100644 --- a/include/spdlog/details/async_log_helper.h +++ b/include/spdlog/details/async_log_helper.h @@ -207,10 +207,10 @@ inline spdlog::details::async_log_helper::async_log_helper( const std::function& worker_warmup_cb, const std::chrono::milliseconds& flush_interval_ms, const std::function& worker_teardown_cb): - _formatter(formatter), + _formatter(std::move(formatter)), _sinks(sinks), _q(queue_size), - _err_handler(err_handler), + _err_handler(std::move(err_handler)), _flush_requested(false), _terminate_requested(false), _overflow_policy(overflow_policy), @@ -349,10 +349,9 @@ inline void spdlog::details::async_log_helper::handle_flush_interval(log_clock:: inline void spdlog::details::async_log_helper::set_formatter(formatter_ptr msg_formatter) { - _formatter = msg_formatter; + _formatter = std::move(msg_formatter); } - // spin, yield or sleep. use the time passed since last message as a hint inline void spdlog::details::async_log_helper::sleep_or_yield(const spdlog::log_clock::time_point& now, const spdlog::log_clock::time_point& last_op_time) { @@ -389,8 +388,5 @@ inline void spdlog::details::async_log_helper::wait_empty_q() inline void spdlog::details::async_log_helper::set_error_handler(spdlog::log_err_handler err_handler) { - _err_handler = err_handler; + _err_handler = std::move(err_handler); } - - - diff --git a/include/spdlog/details/async_logger_impl.h b/include/spdlog/details/async_logger_impl.h index 83732117..d9a1e424 100644 --- a/include/spdlog/details/async_logger_impl.h +++ b/include/spdlog/details/async_logger_impl.h @@ -48,7 +48,7 @@ inline spdlog::async_logger::async_logger(const std::string& logger_name, const std::function& worker_teardown_cb) : async_logger(logger_name, { - single_sink + std::move(single_sink) }, queue_size, overflow_policy, worker_warmup_cb, flush_interval_ms, worker_teardown_cb) {} diff --git a/include/spdlog/details/logger_impl.h b/include/spdlog/details/logger_impl.h index df69102d..e45a6d69 100644 --- a/include/spdlog/details/logger_impl.h +++ b/include/spdlog/details/logger_impl.h @@ -39,7 +39,7 @@ inline spdlog::logger::logger(const std::string& logger_name, sinks_init_list si inline spdlog::logger::logger(const std::string& logger_name, spdlog::sink_ptr single_sink): logger(logger_name, { - single_sink + std::move(single_sink) }) {} @@ -49,7 +49,7 @@ inline spdlog::logger::~logger() = default; inline void spdlog::logger::set_formatter(spdlog::formatter_ptr msg_formatter) { - _set_formatter(msg_formatter); + _set_formatter(std::move(msg_formatter)); } inline void spdlog::logger::set_pattern(const std::string& pattern, pattern_time_type pattern_time) @@ -281,7 +281,7 @@ inline void spdlog::logger::set_level(spdlog::level::level_enum log_level) inline void spdlog::logger::set_error_handler(spdlog::log_err_handler err_handler) { - _err_handler = err_handler; + _err_handler = std::move(err_handler); } inline spdlog::log_err_handler spdlog::logger::error_handler() @@ -289,7 +289,6 @@ inline spdlog::log_err_handler spdlog::logger::error_handler() return _err_handler; } - inline void spdlog::logger::flush_on(level::level_enum log_level) { _flush_level.store(log_level); @@ -330,9 +329,10 @@ inline void spdlog::logger::_set_pattern(const std::string& pattern, pattern_tim { _formatter = std::make_shared(pattern, pattern_time); } + inline void spdlog::logger::_set_formatter(formatter_ptr msg_formatter) { - _formatter = msg_formatter; + _formatter = std::move(msg_formatter); } inline void spdlog::logger::flush() diff --git a/include/spdlog/details/spdlog_impl.h b/include/spdlog/details/spdlog_impl.h index 9733a733..003aff16 100644 --- a/include/spdlog/details/spdlog_impl.h +++ b/include/spdlog/details/spdlog_impl.h @@ -34,7 +34,7 @@ inline void spdlog::register_logger(std::shared_ptr logger) { - return details::registry::instance().register_logger(logger); + return details::registry::instance().register_logger(std::move(logger)); } inline std::shared_ptr spdlog::get(const std::string& name) @@ -183,13 +183,11 @@ inline std::shared_ptr spdlog::create(const std::string& logger_ } //Create logger with multiple sinks - inline std::shared_ptr spdlog::create(const std::string& logger_name, spdlog::sinks_init_list sinks) { return details::registry::instance().create(logger_name, sinks); } - template inline std::shared_ptr spdlog::create(const std::string& logger_name, Args... args) { @@ -197,7 +195,6 @@ inline std::shared_ptr spdlog::create(const std::string& logger_ return details::registry::instance().create(logger_name, { sink }); } - template inline std::shared_ptr spdlog::create(const std::string& logger_name, const It& sinks_begin, const It& sinks_end) { @@ -224,7 +221,7 @@ inline std::shared_ptr spdlog::create_async(const std::string& l inline void spdlog::set_formatter(spdlog::formatter_ptr f) { - details::registry::instance().formatter(f); + details::registry::instance().formatter(std::move(f)); } inline void spdlog::set_pattern(const std::string& format_string) @@ -244,10 +241,9 @@ inline void spdlog::flush_on(level::level_enum log_level) inline void spdlog::set_error_handler(log_err_handler handler) { - return details::registry::instance().set_error_handler(handler); + return details::registry::instance().set_error_handler(std::move(handler)); } - inline void spdlog::set_async_mode(size_t queue_size, const async_overflow_policy overflow_policy, const std::function& worker_warmup_cb, const std::chrono::milliseconds& flush_interval_ms, const std::function& worker_teardown_cb) { details::registry::instance().set_async_mode(queue_size, overflow_policy, worker_warmup_cb, flush_interval_ms, worker_teardown_cb); @@ -260,7 +256,7 @@ inline void spdlog::set_sync_mode() inline void spdlog::apply_all(std::function)> fun) { - details::registry::instance().apply_all(fun); + details::registry::instance().apply_all(std::move(fun)); } inline void spdlog::drop_all() diff --git a/tests/test_pattern_formatter.cpp b/tests/test_pattern_formatter.cpp index e80fd37d..b8810c96 100644 --- a/tests/test_pattern_formatter.cpp +++ b/tests/test_pattern_formatter.cpp @@ -1,7 +1,7 @@ #include "includes.h" // log to str and return it -static std::string log_to_str(const std::string& msg, std::shared_ptr formatter = nullptr) +static std::string log_to_str(const std::string& msg, const std::shared_ptr& formatter = nullptr) { std::ostringstream oss; auto oss_sink = std::make_shared(oss); @@ -11,6 +11,7 @@ static std::string log_to_str(const std::string& msg, std::shared_ptr("[%L] %v", spdlog::pattern_time_type::local, "\n"); @@ -51,19 +51,11 @@ TEST_CASE("name", "[pattern_formatter]") REQUIRE(log_to_str("Some message", formatter) == "[pattern_tester] Some message\n"); } - TEST_CASE("date MM/DD/YY ", "[pattern_formatter]") { - using namespace::std::chrono; auto formatter = std::make_shared("%D %v", spdlog::pattern_time_type::local, "\n"); auto now_tm = spdlog::details::os::localtime(); std::stringstream oss; oss << std::setfill('0') << std::setw(2) << now_tm.tm_mon + 1 << "/" << now_tm.tm_mday << "/" << (now_tm.tm_year + 1900) % 1000 << " Some message\n"; REQUIRE(log_to_str("Some message", formatter) == oss.str()); } - - - - - -