code formatting and clang tidy warnings fixes
This commit is contained in:
		@@ -28,7 +28,7 @@ Very fast, header only, C++ logging library. [ below).
 | 
					* Very fast - performance is the primary goal (see [benchmarks](#benchmarks) below).
 | 
				
			||||||
* Headers only, just copy and use.
 | 
					* 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)
 | 
					* Fast asynchronous mode (optional)
 | 
				
			||||||
* [Custom](https://github.com/gabime/spdlog/wiki/3.-Custom-formatting) formatting.
 | 
					* [Custom](https://github.com/gabime/spdlog/wiki/3.-Custom-formatting) formatting.
 | 
				
			||||||
* Conditional Logging
 | 
					* Conditional Logging
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -42,7 +42,7 @@ struct async_factory_impl
 | 
				
			|||||||
        auto ®istry_inst = details::registry::instance();
 | 
					        auto ®istry_inst = details::registry::instance();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        // create global thread pool if not already exists..
 | 
					        // 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();
 | 
					        auto tp = registry_inst.get_tp();
 | 
				
			||||||
        if (tp == nullptr)
 | 
					        if (tp == nullptr)
 | 
				
			||||||
        {
 | 
					        {
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -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_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_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_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,
 | 
					    async_logger(std::string logger_name, sink_ptr single_sink, std::weak_ptr<details::thread_pool> tp,
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -138,8 +138,8 @@ public:
 | 
				
			|||||||
        : runtime_error(msg)
 | 
					        : runtime_error(msg)
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    spdlog_ex(std::string msg, int last_errno)
 | 
					    spdlog_ex(const std::string &msg, int last_errno)
 | 
				
			||||||
        : runtime_error(std::move(msg))
 | 
					        : runtime_error(msg)
 | 
				
			||||||
        , last_errno_(last_errno)
 | 
					        , last_errno_(last_errno)
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -47,7 +47,7 @@ inline void spdlog::async_logger::sink_it_(details::log_msg &msg)
 | 
				
			|||||||
    }
 | 
					    }
 | 
				
			||||||
    else
 | 
					    else
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        throw spdlog_ex("async log: thread pool doens't exist anymore");
 | 
					        throw spdlog_ex("async log: thread pool doesn't exist anymore");
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -5,14 +5,14 @@
 | 
				
			|||||||
//
 | 
					//
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#include "spdlog/details/null_mutex.h"
 | 
					#include "spdlog/details/null_mutex.h"
 | 
				
			||||||
#include "stdio.h"
 | 
					#include <cstdio>
 | 
				
			||||||
#include <mutex>
 | 
					#include <mutex>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
namespace spdlog {
 | 
					namespace spdlog {
 | 
				
			||||||
namespace details {
 | 
					namespace details {
 | 
				
			||||||
struct console_stdout
 | 
					struct console_stdout
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    static FILE *stream()
 | 
					    static std::FILE *stream()
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        return stdout;
 | 
					        return stdout;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
@@ -26,7 +26,7 @@ struct console_stdout
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
struct console_stderr
 | 
					struct console_stderr
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    static FILE *stream()
 | 
					    static std::FILE *stream()
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        return stderr;
 | 
					        return stderr;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -69,7 +69,7 @@ static const char *ampm(const tm &t)
 | 
				
			|||||||
    return t.tm_hour >= 12 ? "PM" : "AM";
 | 
					    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;
 | 
					    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
 | 
					    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);
 | 
					        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));
 | 
					                    formatters_.push_back(std::move(user_chars));
 | 
				
			||||||
                }
 | 
					                }
 | 
				
			||||||
                // if(
 | 
					 | 
				
			||||||
                if (++it != end)
 | 
					                if (++it != end)
 | 
				
			||||||
                {
 | 
					                {
 | 
				
			||||||
                    handle_flag_(*it);
 | 
					                    handle_flag_(*it);
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -23,7 +23,7 @@ namespace details {
 | 
				
			|||||||
class periodic_worker
 | 
					class periodic_worker
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
public:
 | 
					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());
 | 
					        active_ = (interval > std::chrono::seconds::zero());
 | 
				
			||||||
        if (!active_)
 | 
					        if (!active_)
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -35,7 +35,7 @@ public:
 | 
				
			|||||||
        std::lock_guard<std::mutex> lock(logger_map_mutex_);
 | 
					        std::lock_guard<std::mutex> lock(logger_map_mutex_);
 | 
				
			||||||
        auto logger_name = new_logger->name();
 | 
					        auto logger_name = new_logger->name();
 | 
				
			||||||
        throw_if_exists_(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)
 | 
					    void register_and_init(std::shared_ptr<logger> new_logger)
 | 
				
			||||||
@@ -56,7 +56,7 @@ public:
 | 
				
			|||||||
        new_logger->flush_on(flush_level_);
 | 
					        new_logger->flush_on(flush_level_);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        // add to registry
 | 
					        // 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)
 | 
					    std::shared_ptr<logger> get(const std::string &logger_name)
 | 
				
			||||||
@@ -126,7 +126,7 @@ public:
 | 
				
			|||||||
        err_handler_ = handler;
 | 
					        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_);
 | 
					        std::lock_guard<std::mutex> lock(logger_map_mutex_);
 | 
				
			||||||
        for (auto &l : loggers_)
 | 
					        for (auto &l : loggers_)
 | 
				
			||||||
@@ -189,11 +189,7 @@ private:
 | 
				
			|||||||
    {
 | 
					    {
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    ~registry()
 | 
					    ~registry() = default;
 | 
				
			||||||
    {
 | 
					 | 
				
			||||||
        /*std::lock_guard<std::mutex> lock(flusher_mutex_);
 | 
					 | 
				
			||||||
        periodic_flusher_.reset();*/
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
    void throw_if_exists_(const std::string &logger_name)
 | 
					    void throw_if_exists_(const std::string &logger_name)
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -122,7 +122,7 @@ public:
 | 
				
			|||||||
        }
 | 
					        }
 | 
				
			||||||
        for (size_t i = 0; i < threads_n; i++)
 | 
					        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);
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -30,7 +30,7 @@ public:
 | 
				
			|||||||
    base_sink(const base_sink &) = delete;
 | 
					    base_sink(const base_sink &) = delete;
 | 
				
			||||||
    base_sink &operator=(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_);
 | 
					        std::lock_guard<Mutex> lock(mutex_);
 | 
				
			||||||
        sink_it_(msg);
 | 
					        sink_it_(msg);
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -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)
 | 
					        : level_(level::trace)
 | 
				
			||||||
        , formatter_(std::move(formatter)){};
 | 
					        , formatter_(std::move(formatter)){};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -19,7 +19,7 @@ namespace spdlog {
 | 
				
			|||||||
namespace sinks {
 | 
					namespace sinks {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
template<typename TargetStream, typename ConsoleMutex>
 | 
					template<typename TargetStream, typename ConsoleMutex>
 | 
				
			||||||
class stdout_sink : public sink
 | 
					class stdout_sink SPDLOG_FINAL : public sink
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
public:
 | 
					public:
 | 
				
			||||||
    using mutex_t = typename ConsoleMutex::mutex_t;
 | 
					    using mutex_t = typename ConsoleMutex::mutex_t;
 | 
				
			||||||
@@ -28,7 +28,7 @@ public:
 | 
				
			|||||||
        , file_(TargetStream::stream())
 | 
					        , file_(TargetStream::stream())
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    ~stdout_sink() = default;
 | 
					    ~stdout_sink() override = default;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    stdout_sink(const stdout_sink &other) = delete;
 | 
					    stdout_sink(const stdout_sink &other) = delete;
 | 
				
			||||||
    stdout_sink &operator=(const stdout_sink &other) = delete;
 | 
					    stdout_sink &operator=(const stdout_sink &other) = delete;
 | 
				
			||||||
@@ -48,13 +48,13 @@ public:
 | 
				
			|||||||
        fflush(file_);
 | 
					        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_);
 | 
					        std::lock_guard<mutex_t> lock(mutex_);
 | 
				
			||||||
        formatter_ = std::unique_ptr<spdlog::formatter>(new pattern_formatter(pattern));
 | 
					        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_);
 | 
					        std::lock_guard<mutex_t> lock(mutex_);
 | 
				
			||||||
        formatter_ = std::move(sink_formatter);
 | 
					        formatter_ = std::move(sink_formatter);
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -24,8 +24,8 @@ class syslog_sink : public base_sink<Mutex>
 | 
				
			|||||||
{
 | 
					{
 | 
				
			||||||
public:
 | 
					public:
 | 
				
			||||||
    //
 | 
					    //
 | 
				
			||||||
    syslog_sink(const std::string &ident = "", int syslog_option = 0, int syslog_facility = LOG_USER)
 | 
					    explicit syslog_sink(std::string ident = "", int syslog_option = 0, int syslog_facility = LOG_USER)
 | 
				
			||||||
        : ident_(ident)
 | 
					        : ident_(std::move(ident))
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        priorities_[static_cast<size_t>(level::trace)] = LOG_DEBUG;
 | 
					        priorities_[static_cast<size_t>(level::trace)] = LOG_DEBUG;
 | 
				
			||||||
        priorities_[static_cast<size_t>(level::debug)] = LOG_DEBUG;
 | 
					        priorities_[static_cast<size_t>(level::debug)] = LOG_DEBUG;
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -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");
 | 
					// 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)
 | 
					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
 | 
					// 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
 | 
					// Apply a user defined function on all registered loggers
 | 
				
			||||||
// Example:
 | 
					// Example:
 | 
				
			||||||
// spdlog::apply_all([&](std::shared_ptr<spdlog::logger> l) {l->flush();});
 | 
					// 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
 | 
					// Drop the reference to the given logger
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user