Skip to content

Commit

Permalink
Bump spdlog from 1.11.0 to 1.12.0 (open-telemetry#3158)
Browse files Browse the repository at this point in the history
  • Loading branch information
Kielek authored Nov 23, 2023
1 parent c28fef5 commit c336ee0
Show file tree
Hide file tree
Showing 44 changed files with 908 additions and 236 deletions.
2 changes: 1 addition & 1 deletion docs/internal/native-dependencies.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ Package is acquired via [Microsoft vcpkg](https://github.com/microsoft/vcpkg)
## spdlog

* Source: <https://github.com/gabime/spdlog>
* Version: 1.11.0
* Version: 1.12.0

### Setup

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ template<async_overflow_policy OverflowPolicy = async_overflow_policy::block>
struct async_factory_impl
{
template<typename Sink, typename... SinkArgs>
static std::shared_ptr<async_logger> create(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();

Expand All @@ -61,13 +61,13 @@ using async_factory = async_factory_impl<async_overflow_policy::block>;
using async_factory_nonblock = async_factory_impl<async_overflow_policy::overrun_oldest>;

template<typename Sink, typename... SinkArgs>
inline std::shared_ptr<spdlog::logger> create_async(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>(std::move(logger_name), std::forward<SinkArgs>(sink_args)...);
}

template<typename Sink, typename... SinkArgs>
inline std::shared_ptr<spdlog::logger> create_async_nb(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>(std::move(logger_name), std::forward<SinkArgs>(sink_args)...);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,29 +24,27 @@ SPDLOG_INLINE spdlog::async_logger::async_logger(
{}

// send the log message to the thread pool
SPDLOG_INLINE void spdlog::async_logger::sink_it_(const details::log_msg &msg)
SPDLOG_INLINE void spdlog::async_logger::sink_it_(const details::log_msg &msg){
SPDLOG_TRY{if (auto pool_ptr = thread_pool_.lock()){pool_ptr->post_log(shared_from_this(), msg, overflow_policy_);
}
else
{
if (auto pool_ptr = thread_pool_.lock())
{
pool_ptr->post_log(shared_from_this(), msg, overflow_policy_);
}
else
{
throw_spdlog_ex("async log: thread pool doesn't exist anymore");
}
throw_spdlog_ex("async log: thread pool doesn't exist anymore");
}
}
SPDLOG_LOGGER_CATCH(msg.source)
}

// send flush request to the thread pool
SPDLOG_INLINE void spdlog::async_logger::flush_()
SPDLOG_INLINE void spdlog::async_logger::flush_(){
SPDLOG_TRY{if (auto pool_ptr = thread_pool_.lock()){pool_ptr->post_flush(shared_from_this(), overflow_policy_);
}
else
{
if (auto pool_ptr = thread_pool_.lock())
{
pool_ptr->post_flush(shared_from_this(), overflow_policy_);
}
else
{
throw_spdlog_ex("async flush: thread pool doesn't exist anymore");
}
throw_spdlog_ex("async flush: thread pool doesn't exist anymore");
}
}
SPDLOG_LOGGER_CATCH(source_loc())
}

//
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,12 @@
#include <cstdio>

#ifdef SPDLOG_USE_STD_FORMAT
# include <string_view>
# include <version>
# if __cpp_lib_format >= 202207L
# include <format>
# else
# include <string_view>
# endif
#endif

#ifdef SPDLOG_COMPILED_LIB
Expand Down Expand Up @@ -59,14 +64,14 @@
#if defined(_MSC_VER) && (_MSC_VER < 1900)
# define SPDLOG_NOEXCEPT _NOEXCEPT
# define SPDLOG_CONSTEXPR
# define SPDLOG_CONSTEXPR_FUNC
# define SPDLOG_CONSTEXPR_FUNC inline
#else
# define SPDLOG_NOEXCEPT noexcept
# define SPDLOG_CONSTEXPR constexpr
# if __cplusplus >= 201402L
# define SPDLOG_CONSTEXPR_FUNC constexpr
# else
# define SPDLOG_CONSTEXPR_FUNC
# define SPDLOG_CONSTEXPR_FUNC inline
# endif
#endif

Expand Down Expand Up @@ -102,7 +107,8 @@
# define SPDLOG_TRY try
# define SPDLOG_THROW(ex) throw(ex)
# define SPDLOG_CATCH_STD \
catch (const std::exception &) {}
catch (const std::exception &) \
{}
#endif

namespace spdlog {
Expand Down Expand Up @@ -134,7 +140,11 @@ using string_view_t = std::string_view;
using memory_buf_t = std::string;

template<typename... Args>
# if __cpp_lib_format >= 202207L
using format_string_t = std::format_string<Args...>;
# else
using format_string_t = std::string_view;
# endif

template<class T, class Char = char>
struct is_convertible_to_basic_format_string : std::integral_constant<bool, std::is_convertible<T, std::basic_string_view<Char>>::value>
Expand All @@ -145,7 +155,11 @@ using wstring_view_t = std::wstring_view;
using wmemory_buf_t = std::wstring;

template<typename... Args>
# if __cpp_lib_format >= 202207L
using wformat_string_t = std::wformat_string<Args...>;
# else
using wformat_string_t = std::wstring_view;
# endif
# endif
# define SPDLOG_BUF_TO_STRING(x) x
#else // use fmt lib instead of std::format
Expand All @@ -160,12 +174,19 @@ using format_string_t = fmt::format_string<Args...>;
template<class T>
using remove_cvref_t = typename std::remove_cv<typename std::remove_reference<T>::type>::type;

template<typename Char>
# if FMT_VERSION >= 90101
using fmt_runtime_string = fmt::runtime_format_string<Char>;
# else
using fmt_runtime_string = fmt::basic_runtime<Char>;
# endif

// clang doesn't like SFINAE disabled constructor in std::is_convertible<> so have to repeat the condition from basic_format_string here,
// in addition, fmt::basic_runtime<Char> is only convertible to basic_format_string<Char> but not basic_string_view<Char>
template<class T, class Char = char>
struct is_convertible_to_basic_format_string
: std::integral_constant<bool,
std::is_convertible<T, fmt::basic_string_view<Char>>::value || std::is_same<remove_cvref_t<T>, fmt::basic_runtime<Char>>::value>
std::is_convertible<T, fmt::basic_string_view<Char>>::value || std::is_same<remove_cvref_t<T>, fmt_runtime_string<Char>>::value>
{};

# if defined(SPDLOG_WCHAR_FILENAMES) || defined(SPDLOG_WCHAR_TO_UTF8_SUPPORT)
Expand Down Expand Up @@ -323,6 +344,44 @@ struct file_event_handlers

namespace details {

// to_string_view

SPDLOG_CONSTEXPR_FUNC spdlog::string_view_t to_string_view(const memory_buf_t &buf) SPDLOG_NOEXCEPT
{
return spdlog::string_view_t{buf.data(), buf.size()};
}

SPDLOG_CONSTEXPR_FUNC spdlog::string_view_t to_string_view(spdlog::string_view_t str) SPDLOG_NOEXCEPT
{
return str;
}

#if defined(SPDLOG_WCHAR_FILENAMES) || defined(SPDLOG_WCHAR_TO_UTF8_SUPPORT)
SPDLOG_CONSTEXPR_FUNC spdlog::wstring_view_t to_string_view(const wmemory_buf_t &buf) SPDLOG_NOEXCEPT
{
return spdlog::wstring_view_t{buf.data(), buf.size()};
}

SPDLOG_CONSTEXPR_FUNC spdlog::wstring_view_t to_string_view(spdlog::wstring_view_t str) SPDLOG_NOEXCEPT
{
return str;
}
#endif

#ifndef SPDLOG_USE_STD_FORMAT
template<typename T, typename... Args>
inline fmt::basic_string_view<T> to_string_view(fmt::basic_format_string<T, Args...> fmt)
{
return fmt;
}
#elif __cpp_lib_format >= 202207L
template<typename T, typename... Args>
SPDLOG_CONSTEXPR_FUNC std::basic_string_view<T> to_string_view(std::basic_format_string<T, Args...> fmt) SPDLOG_NOEXCEPT
{
return fmt.get();
}
#endif

// make_unique support for pre c++14

#if __cplusplus >= 201402L // C++14 and beyond
Expand All @@ -333,7 +392,7 @@ template<bool B, class T = void>
using enable_if_t = typename std::enable_if<B, T>::type;

template<typename T, typename... Args>
std::unique_ptr<T> make_unique(Args &&... args)
std::unique_ptr<T> make_unique(Args &&...args)
{
static_assert(!std::is_array<T>::value, "arrays not supported");
return std::unique_ptr<T>(new T(std::forward<Args>(args)...));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,12 @@ SPDLOG_INLINE void backtracer::push_back(const log_msg &msg)
messages_.push_back(log_msg_buffer{msg});
}

SPDLOG_INLINE bool backtracer::empty() const
{
std::lock_guard<std::mutex> lock{mutex_};
return messages_.empty();
}

// pop all items in the q and apply the given fun on each of them.
SPDLOG_INLINE void backtracer::foreach_pop(std::function<void(const details::log_msg &)> fun)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ class SPDLOG_API backtracer
void disable();
bool enabled() const;
void push_back(const log_msg &msg);
bool empty() const;

// pop all items in the q and apply the given fun on each of them.
void foreach_pop(std::function<void(const details::log_msg &)> fun);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,14 @@ SPDLOG_INLINE void file_helper::flush()
}
}

SPDLOG_INLINE void file_helper::sync()
{
if (!os::fsync(fd_))
{
throw_spdlog_ex("Failed to fsync file " + os::filename_to_str(filename_), errno);
}
}

SPDLOG_INLINE void file_helper::close()
{
if (fd_ != nullptr)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ class SPDLOG_API file_helper
void open(const filename_t &fname, bool truncate = false);
void reopen(bool truncate);
void flush();
void sync();
void close();
void write(const memory_buf_t &buf);
size_t size() const;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,6 @@ namespace spdlog {
namespace details {
namespace fmt_helper {

inline spdlog::string_view_t to_string_view(const memory_buf_t &buf) SPDLOG_NOEXCEPT
{
return spdlog::string_view_t{buf.data(), buf.size()};
}

inline void append_string_view(spdlog::string_view_t view, memory_buf_t &dest)
{
auto *buf_ptr = view.data();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ class mpmc_blocking_queue
push_cv_.notify_one();
}

// try to dequeue item. if no item found. wait up to timeout and try again
// dequeue with a timeout.
// Return true, if succeeded dequeue item, false otherwise
bool dequeue_for(T &popped_item, std::chrono::milliseconds wait_duration)
{
Expand All @@ -66,6 +66,18 @@ class mpmc_blocking_queue
return true;
}

// blocking dequeue without a timeout.
void dequeue(T &popped_item)
{
{
std::unique_lock<std::mutex> lock(queue_mutex_);
push_cv_.wait(lock, [this] { return !this->q_.empty(); });
popped_item = std::move(q_.front());
q_.pop_front();
}
pop_cv_.notify_one();
}

#else
// apparently mingw deadlocks if the mutex is released before cv.notify_one(),
// so release the mutex at the very end each function.
Expand All @@ -87,7 +99,7 @@ class mpmc_blocking_queue
push_cv_.notify_one();
}

// try to dequeue item. if no item found. wait up to timeout and try again
// dequeue with a timeout.
// Return true, if succeeded dequeue item, false otherwise
bool dequeue_for(T &popped_item, std::chrono::milliseconds wait_duration)
{
Expand All @@ -102,6 +114,16 @@ class mpmc_blocking_queue
return true;
}

// blocking dequeue without a timeout.
void dequeue(T &popped_item)
{
std::unique_lock<std::mutex> lock(queue_mutex_);
push_cv_.wait(lock, [this] { return !this->q_.empty(); });
popped_item = std::move(q_.front());
q_.pop_front();
pop_cv_.notify_one();
}

#endif

size_t overrun_counter()
Expand Down
Loading

0 comments on commit c336ee0

Please sign in to comment.