Unverified Commit f830ef05 authored by Tommaso Tocci's avatar Tommaso Tocci
Browse files

deps: update spdlog v1.2.0 -> v1.3.1

parent 6cde594f
Loading
Loading
Loading
Loading
+7 −7
Original line number Original line Diff line number Diff line
@@ -37,7 +37,7 @@ template<async_overflow_policy OverflowPolicy = async_overflow_policy::block>
struct async_factory_impl
struct async_factory_impl
{
{
    template<typename Sink, typename... SinkArgs>
    template<typename Sink, typename... SinkArgs>
    static std::shared_ptr<async_logger> create(const std::string &logger_name, SinkArgs &&... args)
    static std::shared_ptr<async_logger> create(std::string logger_name, SinkArgs &&... args)
    {
    {
        auto &registry_inst = details::registry::instance();
        auto &registry_inst = details::registry::instance();


@@ -51,8 +51,8 @@ struct async_factory_impl
        }
        }


        auto sink = std::make_shared<Sink>(std::forward<SinkArgs>(args)...);
        auto sink = std::make_shared<Sink>(std::forward<SinkArgs>(args)...);
        auto new_logger = std::make_shared<async_logger>(logger_name, std::move(sink), std::move(tp), OverflowPolicy);
        auto new_logger = std::make_shared<async_logger>(std::move(logger_name), std::move(sink), std::move(tp), OverflowPolicy);
        registry_inst.register_and_init(new_logger);
        registry_inst.initialize_logger(new_logger);
        return new_logger;
        return new_logger;
    }
    }
};
};
@@ -61,15 +61,15 @@ using async_factory = async_factory_impl<async_overflow_policy::block>;
using async_factory_nonblock = async_factory_impl<async_overflow_policy::overrun_oldest>;
using async_factory_nonblock = async_factory_impl<async_overflow_policy::overrun_oldest>;


template<typename Sink, typename... SinkArgs>
template<typename Sink, typename... SinkArgs>
inline std::shared_ptr<spdlog::logger> create_async(const std::string &logger_name, SinkArgs &&... sink_args)
inline std::shared_ptr<spdlog::logger> create_async(std::string logger_name, SinkArgs &&... sink_args)
{
{
    return async_factory::create<Sink>(logger_name, std::forward<SinkArgs>(sink_args)...);
    return async_factory::create<Sink>(std::move(logger_name), std::forward<SinkArgs>(sink_args)...);
}
}


template<typename Sink, typename... SinkArgs>
template<typename Sink, typename... SinkArgs>
inline std::shared_ptr<spdlog::logger> create_async_nb(const std::string &logger_name, SinkArgs &&... sink_args)
inline std::shared_ptr<spdlog::logger> create_async_nb(std::string logger_name, SinkArgs &&... sink_args)
{
{
    return async_factory_nonblock::create<Sink>(logger_name, std::forward<SinkArgs>(sink_args)...);
    return async_factory_nonblock::create<Sink>(std::move(logger_name), std::forward<SinkArgs>(sink_args)...);
}
}


// set global thread pool.
// set global thread pool.
+87 −30
Original line number Original line Diff line number Diff line
@@ -14,6 +14,7 @@
#include <memory>
#include <memory>
#include <stdexcept>
#include <stdexcept>
#include <string>
#include <string>
#include <cstring>
#include <type_traits>
#include <type_traits>
#include <unordered_map>
#include <unordered_map>


@@ -24,6 +25,8 @@


#include "spdlog/details/null_mutex.h"
#include "spdlog/details/null_mutex.h"


#include "spdlog/fmt/fmt.h"

// visual studio upto 2013 does not support noexcept nor constexpr
// visual studio upto 2013 does not support noexcept nor constexpr
#if defined(_MSC_VER) && (_MSC_VER < 1900)
#if defined(_MSC_VER) && (_MSC_VER < 1900)
#define SPDLOG_NOEXCEPT throw()
#define SPDLOG_NOEXCEPT throw()
@@ -41,7 +44,29 @@
#define SPDLOG_DEPRECATED
#define SPDLOG_DEPRECATED
#endif
#endif


#include "spdlog/fmt/fmt.h"
// disable thread local on msvc 2013
#ifndef SPDLOG_NO_TLS
#if (defined(_MSC_VER) && (_MSC_VER < 1900)) || defined(__cplusplus_winrt)
#define SPDLOG_NO_TLS 1
#endif
#endif

// Get the basename of __FILE__ (at compile time if possible)
#if FMT_HAS_FEATURE(__builtin_strrchr)
#define SPDLOG_STRRCHR(str, sep) __builtin_strrchr(str, sep)
#else
#define SPDLOG_STRRCHR(str, sep) strrchr(str, sep)
#endif //__builtin_strrchr not defined

#ifdef _WIN32
#define SPDLOG_FILE_BASENAME(file) SPDLOG_STRRCHR("\\" file, '\\') + 1
#else
#define SPDLOG_FILE_BASENAME(file) SPDLOG_STRRCHR("/" file, '/') + 1
#endif

#ifndef SPDLOG_FUNCTION
#define SPDLOG_FUNCTION __FUNCTION__
#endif


namespace spdlog {
namespace spdlog {


@@ -56,23 +81,42 @@ using sink_ptr = std::shared_ptr<sinks::sink>;
using sinks_init_list = std::initializer_list<sink_ptr>;
using sinks_init_list = std::initializer_list<sink_ptr>;
using log_err_handler = std::function<void(const std::string &err_msg)>;
using log_err_handler = std::function<void(const std::string &err_msg)>;


// string_view type - either std::string_view or fmt::string_view (pre c++17)
#if defined(FMT_USE_STD_STRING_VIEW)
using string_view_t = std::string_view;
#else
using string_view_t = fmt::string_view;
#endif

#if defined(SPDLOG_NO_ATOMIC_LEVELS)
#if defined(SPDLOG_NO_ATOMIC_LEVELS)
using level_t = details::null_atomic_int;
using level_t = details::null_atomic_int;
#else
#else
using level_t = std::atomic<int>;
using level_t = std::atomic<int>;
#endif
#endif


#define SPDLOG_LEVEL_TRACE 0
#define SPDLOG_LEVEL_DEBUG 1
#define SPDLOG_LEVEL_INFO 2
#define SPDLOG_LEVEL_WARN 3
#define SPDLOG_LEVEL_ERROR 4
#define SPDLOG_LEVEL_CRITICAL 5
#define SPDLOG_LEVEL_OFF 6

#if !defined(SPDLOG_ACTIVE_LEVEL)
#define SPDLOG_ACTIVE_LEVEL SPDLOG_LEVEL_INFO
#endif

// Log level enum
// Log level enum
namespace level {
namespace level {
enum level_enum
enum level_enum
{
{
    trace = 0,
    trace = SPDLOG_LEVEL_TRACE,
    debug = 1,
    debug = SPDLOG_LEVEL_DEBUG,
    info = 2,
    info = SPDLOG_LEVEL_INFO,
    warn = 3,
    warn = SPDLOG_LEVEL_WARN,
    err = 4,
    err = SPDLOG_LEVEL_ERROR,
    critical = 5,
    critical = SPDLOG_LEVEL_CRITICAL,
    off = 6
    off = SPDLOG_LEVEL_OFF,
};
};


#if !defined(SPDLOG_LEVEL_NAMES)
#if !defined(SPDLOG_LEVEL_NAMES)
@@ -81,13 +125,13 @@ enum level_enum
        "trace", "debug", "info", "warning", "error", "critical", "off"                                                                    \
        "trace", "debug", "info", "warning", "error", "critical", "off"                                                                    \
    }
    }
#endif
#endif
static const char *level_names[] SPDLOG_LEVEL_NAMES;


static string_view_t level_string_views[] SPDLOG_LEVEL_NAMES;
static const char *short_level_names[]{"T", "D", "I", "W", "E", "C", "O"};
static const char *short_level_names[]{"T", "D", "I", "W", "E", "C", "O"};


inline const char *to_c_str(spdlog::level::level_enum l) SPDLOG_NOEXCEPT
inline string_view_t &to_string_view(spdlog::level::level_enum l) SPDLOG_NOEXCEPT
{
{
    return level_names[l];
    return level_string_views[l];
}
}


inline const char *to_short_c_str(spdlog::level::level_enum l) SPDLOG_NOEXCEPT
inline const char *to_short_c_str(spdlog::level::level_enum l) SPDLOG_NOEXCEPT
@@ -97,17 +141,16 @@ inline const char *to_short_c_str(spdlog::level::level_enum l) SPDLOG_NOEXCEPT


inline spdlog::level::level_enum from_str(const std::string &name) SPDLOG_NOEXCEPT
inline spdlog::level::level_enum from_str(const std::string &name) SPDLOG_NOEXCEPT
{
{
    static std::unordered_map<std::string, level_enum> name_to_level = // map string->level
    int level = 0;
        {{level_names[0], level::trace},                               // trace
    for (const auto &level_str : level_string_views)
            {level_names[1], level::debug},                            // debug
    {
            {level_names[2], level::info},                             // info
        if (level_str == name)
            {level_names[3], level::warn},                             // warn
        {
            {level_names[4], level::err},                              // err
            return static_cast<level::level_enum>(level);
            {level_names[5], level::critical},                         // critical
        }
            {level_names[6], level::off}};                             // off
        level++;

    }
    auto lvl_it = name_to_level.find(name);
    return level::off;
    return lvl_it != name_to_level.end() ? lvl_it->second : level::off;
}
}


using level_hasher = std::hash<int>;
using level_hasher = std::hash<int>;
@@ -159,16 +202,30 @@ using filename_t = std::wstring;
using filename_t = std::string;
using filename_t = std::string;
#endif
#endif


#define SPDLOG_CATCH_AND_HANDLE                                                                                                            \
struct source_loc
    catch (const std::exception &ex)                                                                                                       \
{
    {                                                                                                                                      \
    SPDLOG_CONSTEXPR source_loc()
        err_handler_(ex.what());                                                                                                           \
        : filename{""}
    }                                                                                                                                      \
        , line{0}
    catch (...)                                                                                                                            \
        , funcname{""}
    {                                                                                                                                      \
    {
        err_handler_("Unknown exeption in logger");                                                                                        \
    }
    SPDLOG_CONSTEXPR source_loc(const char *filename, int line, const char *funcname)
        : filename{filename}
        , line{static_cast<uint32_t>(line)}
        , funcname{funcname}
    {
    }
    }


    SPDLOG_CONSTEXPR bool empty() const SPDLOG_NOEXCEPT
    {
        return line == 0;
    }
    const char *filename;
    uint32_t line;
    const char *funcname;
};

namespace details {
namespace details {
// make_unique support for pre c++14
// make_unique support for pre c++14


+4 −4
Original line number Original line Diff line number Diff line
@@ -18,20 +18,20 @@ template<typename It>
inline spdlog::async_logger::async_logger(
inline spdlog::async_logger::async_logger(
    std::string logger_name, It begin, It end, std::weak_ptr<details::thread_pool> tp, async_overflow_policy overflow_policy)
    std::string logger_name, It begin, It end, std::weak_ptr<details::thread_pool> tp, async_overflow_policy overflow_policy)
    : logger(std::move(logger_name), begin, end)
    : logger(std::move(logger_name), begin, end)
    , thread_pool_(tp)
    , thread_pool_(std::move(tp))
    , overflow_policy_(overflow_policy)
    , overflow_policy_(overflow_policy)
{
{
}
}


inline spdlog::async_logger::async_logger(
inline spdlog::async_logger::async_logger(
    std::string logger_name, sinks_init_list sinks_list, std::weak_ptr<details::thread_pool> tp, async_overflow_policy overflow_policy)
    std::string logger_name, sinks_init_list sinks_list, std::weak_ptr<details::thread_pool> tp, async_overflow_policy overflow_policy)
    : async_logger(std::move(logger_name), sinks_list.begin(), sinks_list.end(), tp, overflow_policy)
    : async_logger(std::move(logger_name), sinks_list.begin(), sinks_list.end(), std::move(tp), overflow_policy)
{
{
}
}


inline spdlog::async_logger::async_logger(
inline spdlog::async_logger::async_logger(
    std::string logger_name, sink_ptr single_sink, std::weak_ptr<details::thread_pool> tp, async_overflow_policy overflow_policy)
    std::string logger_name, sink_ptr single_sink, std::weak_ptr<details::thread_pool> tp, async_overflow_policy overflow_policy)
    : async_logger(std::move(logger_name), {single_sink}, tp, overflow_policy)
    : async_logger(std::move(logger_name), {std::move(single_sink)}, std::move(tp), overflow_policy)
{
{
}
}


@@ -43,7 +43,7 @@ inline void spdlog::async_logger::sink_it_(details::log_msg &msg)
#endif
#endif
    if (auto pool_ptr = thread_pool_.lock())
    if (auto pool_ptr = thread_pool_.lock())
    {
    {
        pool_ptr->post_log(shared_from_this(), std::move(msg), overflow_policy_);
        pool_ptr->post_log(shared_from_this(), msg, overflow_policy_);
    }
    }
    else
    else
    {
    {
+1 −1
Original line number Original line Diff line number Diff line
@@ -122,7 +122,7 @@ public:
    // ".mylog" => (".mylog". "")
    // ".mylog" => (".mylog". "")
    // "my_folder/.mylog" => ("my_folder/.mylog", "")
    // "my_folder/.mylog" => ("my_folder/.mylog", "")
    // "my_folder/.mylog.txt" => ("my_folder/.mylog", ".txt")
    // "my_folder/.mylog.txt" => ("my_folder/.mylog", ".txt")
    static std::tuple<filename_t, filename_t> split_by_extenstion(const spdlog::filename_t &fname)
    static std::tuple<filename_t, filename_t> split_by_extension(const spdlog::filename_t &fname)
    {
    {
        auto ext_index = fname.rfind('.');
        auto ext_index = fname.rfind('.');


+49 −54
Original line number Original line Diff line number Diff line
@@ -4,7 +4,8 @@


#pragma once
#pragma once


#include "chrono"
#include <chrono>
#include <type_traits>
#include "spdlog/fmt/fmt.h"
#include "spdlog/fmt/fmt.h"


// Some fmt helpers to efficiently format and pad ints and strings
// Some fmt helpers to efficiently format and pad ints and strings
@@ -13,17 +14,9 @@ namespace details {
namespace fmt_helper {
namespace fmt_helper {


template<size_t Buffer_Size>
template<size_t Buffer_Size>
inline void append_str(const std::string &str, fmt::basic_memory_buffer<char, Buffer_Size> &dest)
inline spdlog::string_view_t to_string_view(const fmt::basic_memory_buffer<char, Buffer_Size> &buf) SPDLOG_NOEXCEPT
{
{
    auto *str_ptr = str.data();
    return spdlog::string_view_t(buf.data(), buf.size());
    dest.append(str_ptr, str_ptr + str.size());
}

template<size_t Buffer_Size>
inline void append_c_str(const char *c_str, fmt::basic_memory_buffer<char, Buffer_Size> &dest)
{
    auto len = std::char_traits<char>::length(c_str);
    dest.append(c_str, c_str + len);
}
}


template<size_t Buffer_Size1, size_t Buffer_Size2>
template<size_t Buffer_Size1, size_t Buffer_Size2>
@@ -33,6 +26,16 @@ inline void append_buf(const fmt::basic_memory_buffer<char, Buffer_Size1> &buf,
    dest.append(buf_ptr, buf_ptr + buf.size());
    dest.append(buf_ptr, buf_ptr + buf.size());
}
}


template<size_t Buffer_Size>
inline void append_string_view(spdlog::string_view_t view, fmt::basic_memory_buffer<char, Buffer_Size> &dest)
{
    auto *buf_ptr = view.data();
    if (buf_ptr != nullptr)
    {
        dest.append(buf_ptr, buf_ptr + view.size());
    }
}

template<typename T, size_t Buffer_Size>
template<typename T, size_t Buffer_Size>
inline void append_int(T n, fmt::basic_memory_buffer<char, Buffer_Size> &dest)
inline void append_int(T n, fmt::basic_memory_buffer<char, Buffer_Size> &dest)
{
{
@@ -40,73 +43,65 @@ inline void append_int(T n, fmt::basic_memory_buffer<char, Buffer_Size> &dest)
    dest.append(i.data(), i.data() + i.size());
    dest.append(i.data(), i.data() + i.size());
}
}


template<typename T>
inline unsigned count_digits(T n)
{
    using count_type = typename std::conditional<(sizeof(T) > sizeof(uint32_t)), uint64_t, uint32_t>::type;
    return static_cast<unsigned>(fmt::internal::count_digits(static_cast<count_type>(n)));
}

template<size_t Buffer_Size>
template<size_t Buffer_Size>
inline void pad2(int n, fmt::basic_memory_buffer<char, Buffer_Size> &dest)
inline void pad2(int n, fmt::basic_memory_buffer<char, Buffer_Size> &dest)
{
{
    if (n > 99)
    if (n > 99)
    {
    {
        append_int(n, dest);
        append_int(n, dest);
        return;
    }
    }
    if (n > 9) // 10-99
    else if (n > 9) // 10-99
    {
    {
        dest.push_back(static_cast<char>('0' + n / 10));
        dest.push_back(static_cast<char>('0' + n / 10));
        dest.push_back(static_cast<char>('0' + n % 10));
        dest.push_back(static_cast<char>('0' + n % 10));
        return;
    }
    }
    if (n >= 0) // 0-9
    else if (n >= 0) // 0-9
    {
    {
        dest.push_back('0');
        dest.push_back('0');
        dest.push_back(static_cast<char>('0' + n));
        dest.push_back(static_cast<char>('0' + n));
        return;
    }
    }
    // negatives (unlikely, but just in case, let fmt deal with it)
    else // negatives (unlikely, but just in case, let fmt deal with it)
    {
        fmt::format_to(dest, "{:02}", n);
        fmt::format_to(dest, "{:02}", n);
    }
    }
}


template<size_t Buffer_Size>
template<typename T, size_t Buffer_Size>
inline void pad3(int n, fmt::basic_memory_buffer<char, Buffer_Size> &dest)
inline void pad_uint(T n, unsigned int width, fmt::basic_memory_buffer<char, Buffer_Size> &dest)
{
{
    if (n > 999)
    static_assert(std::is_unsigned<T>::value, "pad_uint must get unsigned T");
    auto digits = count_digits(n);
    if (width > digits)
    {
    {
        const char *zeroes = "0000000000000000000";
        dest.append(zeroes, zeroes + width - digits);
    }
    append_int(n, dest);
    append_int(n, dest);
        return;
}
}


    if (n > 99) // 100-999
template<typename T, size_t Buffer_Size>
inline void pad3(T n, fmt::basic_memory_buffer<char, Buffer_Size> &dest)
{
{
        dest.push_back(static_cast<char>('0' + n / 100));
    pad_uint(n, 3, dest);
        pad2(n % 100, dest);
        return;
}
}
    if (n > 9) // 10-99

template<typename T, size_t Buffer_Size>
inline void pad6(T n, fmt::basic_memory_buffer<char, Buffer_Size> &dest)
{
{
        dest.push_back('0');
    pad_uint(n, 6, dest);
        dest.push_back(static_cast<char>('0' + n / 10));
        dest.push_back(static_cast<char>('0' + n % 10));
        return;
    }
    if (n >= 0)
    {
        dest.push_back('0');
        dest.push_back('0');
        dest.push_back(static_cast<char>('0' + n));
        return;
    }
    // negatives (unlikely, but just in case let fmt deal with it)
    fmt::format_to(dest, "{:03}", n);
}
}


template<size_t Buffer_Size>
template<typename T, size_t Buffer_Size>
inline void pad6(size_t n, fmt::basic_memory_buffer<char, Buffer_Size> &dest)
inline void pad9(T n, fmt::basic_memory_buffer<char, Buffer_Size> &dest)
{
    if (n > 99999)
{
{
        append_int(n, dest);
    pad_uint(n, 9, dest);
        return;
    }
    pad3(static_cast<int>(n / 1000), dest);
    pad3(static_cast<int>(n % 1000), dest);
}
}


// return fraction of a second of the given time_point.
// return fraction of a second of the given time_point.
Loading