diff --git a/README.md b/README.md index 2d9f8143..3b3afba4 100644 --- a/README.md +++ b/README.md @@ -28,7 +28,7 @@ Very fast, header only, C++ logging library. [![Build Status](https://travis-ci. ## Features * Very fast - performance is the primary goal (see [benchmarks](#benchmarks) below). * Headers only, just copy and use. -* Feature rich [call style](#usage-example) using the excellent [fmt](https://github.com/fmtlib/fmt) library. +* Feature rich using the excellent [fmt](https://github.com/fmtlib/fmt) library. * Fast asynchronous mode (optional) * [Custom](https://github.com/gabime/spdlog/wiki/3.-Custom-formatting) formatting. * Conditional Logging diff --git a/include/spdlog/async.h b/include/spdlog/async.h index b67c3329..9c3e9551 100644 --- a/include/spdlog/async.h +++ b/include/spdlog/async.h @@ -42,7 +42,7 @@ struct async_factory_impl auto ®istry_inst = details::registry::instance(); // create global thread pool if not already exists.. - std::lock_guard lock(registry_inst.tp_mutex()); + std::lock_guard tp_lock(registry_inst.tp_mutex()); auto tp = registry_inst.get_tp(); if (tp == nullptr) { diff --git a/include/spdlog/async_logger.h b/include/spdlog/async_logger.h index 2d58f98b..3250f4ad 100644 --- a/include/spdlog/async_logger.h +++ b/include/spdlog/async_logger.h @@ -49,7 +49,7 @@ public: async_logger(std::string logger_name, const It &begin, const It &end, std::weak_ptr tp, async_overflow_policy overflow_policy = async_overflow_policy::block); - async_logger(std::string logger_name, sinks_init_list sinks, std::weak_ptr tp, + async_logger(std::string logger_name, sinks_init_list sinks_list, std::weak_ptr tp, async_overflow_policy overflow_policy = async_overflow_policy::block); async_logger(std::string logger_name, sink_ptr single_sink, std::weak_ptr tp, diff --git a/include/spdlog/common.h b/include/spdlog/common.h index b8d45175..ddb0d28c 100644 --- a/include/spdlog/common.h +++ b/include/spdlog/common.h @@ -138,8 +138,8 @@ public: : runtime_error(msg) { } - spdlog_ex(std::string msg, int last_errno) - : runtime_error(std::move(msg)) + spdlog_ex(const std::string &msg, int last_errno) + : runtime_error(msg) , last_errno_(last_errno) { } diff --git a/include/spdlog/details/async_logger_impl.h b/include/spdlog/details/async_logger_impl.h index a42ade94..47659ddc 100644 --- a/include/spdlog/details/async_logger_impl.h +++ b/include/spdlog/details/async_logger_impl.h @@ -47,7 +47,7 @@ inline void spdlog::async_logger::sink_it_(details::log_msg &msg) } else { - throw spdlog_ex("async log: thread pool doens't exist anymore"); + throw spdlog_ex("async log: thread pool doesn't exist anymore"); } } diff --git a/include/spdlog/details/console_globals.h b/include/spdlog/details/console_globals.h index 52de06a5..4ac7f743 100644 --- a/include/spdlog/details/console_globals.h +++ b/include/spdlog/details/console_globals.h @@ -5,14 +5,14 @@ // #include "spdlog/details/null_mutex.h" -#include "stdio.h" +#include #include namespace spdlog { namespace details { struct console_stdout { - static FILE *stream() + static std::FILE *stream() { return stdout; } @@ -26,7 +26,7 @@ struct console_stdout struct console_stderr { - static FILE *stream() + static std::FILE *stream() { return stderr; } diff --git a/include/spdlog/details/pattern_formatter.h b/include/spdlog/details/pattern_formatter.h index 855ea0d8..dd352ae5 100644 --- a/include/spdlog/details/pattern_formatter.h +++ b/include/spdlog/details/pattern_formatter.h @@ -69,7 +69,7 @@ static const char *ampm(const tm &t) return t.tm_hour >= 12 ? "PM" : "AM"; } -static unsigned int to12h(const tm &t) +static int to12h(const tm &t) { return t.tm_hour > 12 ? t.tm_hour - 12 : t.tm_hour; } @@ -242,7 +242,7 @@ class f_formatter SPDLOG_FINAL : public flag_formatter void format(const details::log_msg &msg, const std::tm &, fmt::memory_buffer &dest) override { auto micros = fmt_helper::time_fraction(msg.time); - fmt_helper::pad6(static_cast(micros.count()), dest); + fmt_helper::pad6(static_cast(micros.count()), dest); } }; @@ -745,7 +745,6 @@ private: { formatters_.push_back(std::move(user_chars)); } - // if( if (++it != end) { handle_flag_(*it); diff --git a/include/spdlog/details/periodic_worker.h b/include/spdlog/details/periodic_worker.h index acc13117..57e5fa77 100644 --- a/include/spdlog/details/periodic_worker.h +++ b/include/spdlog/details/periodic_worker.h @@ -23,7 +23,7 @@ namespace details { class periodic_worker { public: - periodic_worker(std::function callback_fun, std::chrono::seconds interval) + periodic_worker(const std::function &callback_fun, std::chrono::seconds interval) { active_ = (interval > std::chrono::seconds::zero()); if (!active_) diff --git a/include/spdlog/details/registry.h b/include/spdlog/details/registry.h index b3db19a2..adbfd16d 100644 --- a/include/spdlog/details/registry.h +++ b/include/spdlog/details/registry.h @@ -35,7 +35,7 @@ public: std::lock_guard lock(logger_map_mutex_); auto logger_name = new_logger->name(); throw_if_exists_(logger_name); - loggers_[logger_name] = new_logger; + loggers_[logger_name] = std::move(new_logger); } void register_and_init(std::shared_ptr new_logger) @@ -56,7 +56,7 @@ public: new_logger->flush_on(flush_level_); // add to registry - loggers_[logger_name] = new_logger; + loggers_[logger_name] = std::move(new_logger); } std::shared_ptr get(const std::string &logger_name) @@ -126,7 +126,7 @@ public: err_handler_ = handler; } - void apply_all(std::function)> fun) + void apply_all(const std::function)> &fun) { std::lock_guard lock(logger_map_mutex_); for (auto &l : loggers_) @@ -189,11 +189,7 @@ private: { } - ~registry() - { - /*std::lock_guard lock(flusher_mutex_); - periodic_flusher_.reset();*/ - } + ~registry() = default; void throw_if_exists_(const std::string &logger_name) { diff --git a/include/spdlog/details/thread_pool.h b/include/spdlog/details/thread_pool.h index 36c056a6..b45b6d2b 100644 --- a/include/spdlog/details/thread_pool.h +++ b/include/spdlog/details/thread_pool.h @@ -122,7 +122,7 @@ public: } for (size_t i = 0; i < threads_n; i++) { - threads_.emplace_back(std::bind(&thread_pool::worker_loop_, this)); + threads_.emplace_back(&thread_pool::worker_loop_, this); } } diff --git a/include/spdlog/sinks/base_sink.h b/include/spdlog/sinks/base_sink.h index 5a3821bc..43863eae 100644 --- a/include/spdlog/sinks/base_sink.h +++ b/include/spdlog/sinks/base_sink.h @@ -30,7 +30,7 @@ public: base_sink(const base_sink &) = delete; base_sink &operator=(const base_sink &) = delete; - void log(const details::log_msg &msg) SPDLOG_FINAL override + void log(const details::log_msg &msg) SPDLOG_FINAL { std::lock_guard lock(mutex_); sink_it_(msg); diff --git a/include/spdlog/sinks/sink.h b/include/spdlog/sinks/sink.h index 288d5438..cb8aecb4 100644 --- a/include/spdlog/sinks/sink.h +++ b/include/spdlog/sinks/sink.h @@ -20,7 +20,7 @@ public: { } - sink(std::unique_ptr formatter) + explicit sink(std::unique_ptr formatter) : level_(level::trace) , formatter_(std::move(formatter)){}; diff --git a/include/spdlog/sinks/stdout_sinks.h b/include/spdlog/sinks/stdout_sinks.h index 64c0ab70..e12739c1 100644 --- a/include/spdlog/sinks/stdout_sinks.h +++ b/include/spdlog/sinks/stdout_sinks.h @@ -19,7 +19,7 @@ namespace spdlog { namespace sinks { template -class stdout_sink : public sink +class stdout_sink SPDLOG_FINAL : public sink { public: using mutex_t = typename ConsoleMutex::mutex_t; @@ -28,7 +28,7 @@ public: , file_(TargetStream::stream()) { } - ~stdout_sink() = default; + ~stdout_sink() override = default; stdout_sink(const stdout_sink &other) = delete; stdout_sink &operator=(const stdout_sink &other) = delete; @@ -48,13 +48,13 @@ public: fflush(file_); } - void set_pattern(const std::string &pattern) override SPDLOG_FINAL + void set_pattern(const std::string &pattern) override { std::lock_guard lock(mutex_); formatter_ = std::unique_ptr(new pattern_formatter(pattern)); } - void set_formatter(std::unique_ptr sink_formatter) override SPDLOG_FINAL + void set_formatter(std::unique_ptr sink_formatter) override { std::lock_guard lock(mutex_); formatter_ = std::move(sink_formatter); diff --git a/include/spdlog/sinks/syslog_sink.h b/include/spdlog/sinks/syslog_sink.h index e171bf9a..151e7a11 100644 --- a/include/spdlog/sinks/syslog_sink.h +++ b/include/spdlog/sinks/syslog_sink.h @@ -24,8 +24,8 @@ class syslog_sink : public base_sink { public: // - syslog_sink(const std::string &ident = "", int syslog_option = 0, int syslog_facility = LOG_USER) - : ident_(ident) + explicit syslog_sink(std::string ident = "", int syslog_option = 0, int syslog_facility = LOG_USER) + : ident_(std::move(ident)) { priorities_[static_cast(level::trace)] = LOG_DEBUG; priorities_[static_cast(level::debug)] = LOG_DEBUG; diff --git a/include/spdlog/spdlog.h b/include/spdlog/spdlog.h index 2963a2a0..40640ab9 100644 --- a/include/spdlog/spdlog.h +++ b/include/spdlog/spdlog.h @@ -64,7 +64,7 @@ inline void set_formatter(std::unique_ptr formatter) // example: spdlog::set_pattern("%Y-%m-%d %H:%M:%S.%e %l : %v"); inline void set_pattern(std::string pattern, pattern_time_type time_type = pattern_time_type::local) { - set_formatter(std::unique_ptr(new pattern_formatter(pattern, time_type))); + set_formatter(std::unique_ptr(new pattern_formatter(std::move(pattern), time_type))); } // Set global logging level @@ -101,9 +101,9 @@ inline void register_logger(std::shared_ptr logger) // Apply a user defined function on all registered loggers // Example: // spdlog::apply_all([&](std::shared_ptr l) {l->flush();}); -inline void apply_all(std::function)> fun) +inline void apply_all(const std::function)> &fun) { - details::registry::instance().apply_all(std::move(fun)); + details::registry::instance().apply_all(fun); } // Drop the reference to the given logger diff --git a/tests/file_log.cpp b/tests/file_log.cpp index 9ddaae83..6a4d7aee 100644 --- a/tests/file_log.cpp +++ b/tests/file_log.cpp @@ -33,7 +33,7 @@ TEST_CASE("flush_on", "[flush_on]]") logger->info("Test message {}", 1); logger->info("Test message {}", 2); - + REQUIRE(file_contents(filename) == std::string("Should not be flushed\nTest message 1\nTest message 2\n")); REQUIRE(count_lines(filename) == 3); }