From 0b86d6a451ce74adcb79d72b567f40ea04b26092 Mon Sep 17 00:00:00 2001 From: IIFEgit Date: Tue, 26 May 2020 21:35:04 +0100 Subject: [PATCH 1/2] fix deadlock on filename() call --- include/spdlog/sinks/daily_file_sink.h | 8 +------- include/spdlog/sinks/rotating_file_sink-inl.h | 7 ------- include/spdlog/sinks/rotating_file_sink.h | 1 - 3 files changed, 1 insertion(+), 15 deletions(-) diff --git a/include/spdlog/sinks/daily_file_sink.h b/include/spdlog/sinks/daily_file_sink.h index a3843af7..9fae2c30 100644 --- a/include/spdlog/sinks/daily_file_sink.h +++ b/include/spdlog/sinks/daily_file_sink.h @@ -70,12 +70,6 @@ public: } } - filename_t filename() - { - std::lock_guard lock(base_sink::mutex_); - return file_helper_.filename(); - } - protected: void sink_it_(const details::log_msg &msg) override { @@ -155,7 +149,7 @@ private: using details::os::filename_to_str; using details::os::remove_if_exists; - filename_t current_file = filename(); + filename_t current_file = file_helper_.filename(); if (filenames_q_.full()) { auto old_filename = std::move(filenames_q_.front()); diff --git a/include/spdlog/sinks/rotating_file_sink-inl.h b/include/spdlog/sinks/rotating_file_sink-inl.h index d715ebf3..3add7854 100644 --- a/include/spdlog/sinks/rotating_file_sink-inl.h +++ b/include/spdlog/sinks/rotating_file_sink-inl.h @@ -53,13 +53,6 @@ SPDLOG_INLINE filename_t rotating_file_sink::calc_filename(const filename return fmt::format(SPDLOG_FILENAME_T("{}.{}{}"), basename, index, ext); } -template -SPDLOG_INLINE filename_t rotating_file_sink::filename() -{ - std::lock_guard lock(base_sink::mutex_); - return file_helper_.filename(); -} - template SPDLOG_INLINE void rotating_file_sink::sink_it_(const details::log_msg &msg) { diff --git a/include/spdlog/sinks/rotating_file_sink.h b/include/spdlog/sinks/rotating_file_sink.h index e1e85a7d..25a1d495 100644 --- a/include/spdlog/sinks/rotating_file_sink.h +++ b/include/spdlog/sinks/rotating_file_sink.h @@ -24,7 +24,6 @@ class rotating_file_sink final : public base_sink public: rotating_file_sink(filename_t base_filename, std::size_t max_size, std::size_t max_files, bool rotate_on_open = false); static filename_t calc_filename(const filename_t &filename, std::size_t index); - filename_t filename(); protected: void sink_it_(const details::log_msg &msg) override; From 95485ee89b8aa6f2ec1e5449cc2781c755b485b3 Mon Sep 17 00:00:00 2001 From: IIFEgit Date: Tue, 26 May 2020 21:59:57 +0100 Subject: [PATCH 2/2] keep filename as it's public --- include/spdlog/sinks/daily_file_sink.h | 6 ++++++ include/spdlog/sinks/rotating_file_sink-inl.h | 7 +++++++ include/spdlog/sinks/rotating_file_sink.h | 1 + 3 files changed, 14 insertions(+) diff --git a/include/spdlog/sinks/daily_file_sink.h b/include/spdlog/sinks/daily_file_sink.h index 9fae2c30..ce140415 100644 --- a/include/spdlog/sinks/daily_file_sink.h +++ b/include/spdlog/sinks/daily_file_sink.h @@ -70,6 +70,12 @@ public: } } + filename_t filename() + { + std::lock_guard lock(base_sink::mutex_); + return file_helper_.filename(); + } + protected: void sink_it_(const details::log_msg &msg) override { diff --git a/include/spdlog/sinks/rotating_file_sink-inl.h b/include/spdlog/sinks/rotating_file_sink-inl.h index 3add7854..d715ebf3 100644 --- a/include/spdlog/sinks/rotating_file_sink-inl.h +++ b/include/spdlog/sinks/rotating_file_sink-inl.h @@ -53,6 +53,13 @@ SPDLOG_INLINE filename_t rotating_file_sink::calc_filename(const filename return fmt::format(SPDLOG_FILENAME_T("{}.{}{}"), basename, index, ext); } +template +SPDLOG_INLINE filename_t rotating_file_sink::filename() +{ + std::lock_guard lock(base_sink::mutex_); + return file_helper_.filename(); +} + template SPDLOG_INLINE void rotating_file_sink::sink_it_(const details::log_msg &msg) { diff --git a/include/spdlog/sinks/rotating_file_sink.h b/include/spdlog/sinks/rotating_file_sink.h index 25a1d495..e1e85a7d 100644 --- a/include/spdlog/sinks/rotating_file_sink.h +++ b/include/spdlog/sinks/rotating_file_sink.h @@ -24,6 +24,7 @@ class rotating_file_sink final : public base_sink public: rotating_file_sink(filename_t base_filename, std::size_t max_size, std::size_t max_files, bool rotate_on_open = false); static filename_t calc_filename(const filename_t &filename, std::size_t index); + filename_t filename(); protected: void sink_it_(const details::log_msg &msg) override;