code formatting and clang tidy warnings fixes

This commit is contained in:
gabime 2018-08-13 10:30:02 +03:00
parent 4866f2ac05
commit 05d6960ebc
16 changed files with 29 additions and 34 deletions

View File

@ -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

View File

@ -42,7 +42,7 @@ struct async_factory_impl
auto &registry_inst = details::registry::instance();
// create global thread pool if not already exists..
std::lock_guard<std::recursive_mutex> lock(registry_inst.tp_mutex());
std::lock_guard<std::recursive_mutex> tp_lock(registry_inst.tp_mutex());
auto tp = registry_inst.get_tp();
if (tp == nullptr)
{

View File

@ -49,7 +49,7 @@ public:
async_logger(std::string logger_name, const It &begin, const It &end, std::weak_ptr<details::thread_pool> tp,
async_overflow_policy overflow_policy = async_overflow_policy::block);
async_logger(std::string logger_name, sinks_init_list sinks, std::weak_ptr<details::thread_pool> tp,
async_logger(std::string logger_name, sinks_init_list sinks_list, std::weak_ptr<details::thread_pool> tp,
async_overflow_policy overflow_policy = async_overflow_policy::block);
async_logger(std::string logger_name, sink_ptr single_sink, std::weak_ptr<details::thread_pool> tp,

View File

@ -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)
{
}

View File

@ -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");
}
}

View File

@ -5,14 +5,14 @@
//
#include "spdlog/details/null_mutex.h"
#include "stdio.h"
#include <cstdio>
#include <mutex>
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;
}

View File

@ -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<std::chrono::microseconds>(msg.time);
fmt_helper::pad6(static_cast<int>(micros.count()), dest);
fmt_helper::pad6(static_cast<size_t>(micros.count()), dest);
}
};
@ -745,7 +745,6 @@ private:
{
formatters_.push_back(std::move(user_chars));
}
// if(
if (++it != end)
{
handle_flag_(*it);

View File

@ -23,7 +23,7 @@ namespace details {
class periodic_worker
{
public:
periodic_worker(std::function<void()> callback_fun, std::chrono::seconds interval)
periodic_worker(const std::function<void()> &callback_fun, std::chrono::seconds interval)
{
active_ = (interval > std::chrono::seconds::zero());
if (!active_)

View File

@ -35,7 +35,7 @@ public:
std::lock_guard<std::mutex> 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<logger> 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<logger> get(const std::string &logger_name)
@ -126,7 +126,7 @@ public:
err_handler_ = handler;
}
void apply_all(std::function<void(std::shared_ptr<logger>)> fun)
void apply_all(const std::function<void(const std::shared_ptr<logger>)> &fun)
{
std::lock_guard<std::mutex> lock(logger_map_mutex_);
for (auto &l : loggers_)
@ -189,11 +189,7 @@ private:
{
}
~registry()
{
/*std::lock_guard<std::mutex> lock(flusher_mutex_);
periodic_flusher_.reset();*/
}
~registry() = default;
void throw_if_exists_(const std::string &logger_name)
{

View File

@ -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);
}
}

View File

@ -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<Mutex> lock(mutex_);
sink_it_(msg);

View File

@ -20,7 +20,7 @@ public:
{
}
sink(std::unique_ptr<spdlog::pattern_formatter> formatter)
explicit sink(std::unique_ptr<spdlog::pattern_formatter> formatter)
: level_(level::trace)
, formatter_(std::move(formatter)){};

View File

@ -19,7 +19,7 @@ namespace spdlog {
namespace sinks {
template<typename TargetStream, typename ConsoleMutex>
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<mutex_t> lock(mutex_);
formatter_ = std::unique_ptr<spdlog::formatter>(new pattern_formatter(pattern));
}
void set_formatter(std::unique_ptr<spdlog::formatter> sink_formatter) override SPDLOG_FINAL
void set_formatter(std::unique_ptr<spdlog::formatter> sink_formatter) override
{
std::lock_guard<mutex_t> lock(mutex_);
formatter_ = std::move(sink_formatter);

View File

@ -24,8 +24,8 @@ class syslog_sink : public base_sink<Mutex>
{
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<size_t>(level::trace)] = LOG_DEBUG;
priorities_[static_cast<size_t>(level::debug)] = LOG_DEBUG;

View File

@ -64,7 +64,7 @@ inline void set_formatter(std::unique_ptr<spdlog::formatter> 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<spdlog::formatter>(new pattern_formatter(pattern, time_type)));
set_formatter(std::unique_ptr<spdlog::formatter>(new pattern_formatter(std::move(pattern), time_type)));
}
// Set global logging level
@ -101,9 +101,9 @@ inline void register_logger(std::shared_ptr<logger> logger)
// Apply a user defined function on all registered loggers
// Example:
// spdlog::apply_all([&](std::shared_ptr<spdlog::logger> l) {l->flush();});
inline void apply_all(std::function<void(std::shared_ptr<logger>)> fun)
inline void apply_all(const std::function<void(std::shared_ptr<logger>)> &fun)
{
details::registry::instance().apply_all(std::move(fun));
details::registry::instance().apply_all(fun);
}
// Drop the reference to the given logger