diff --git a/include/spdlog/sinks/daily_file_sink.h b/include/spdlog/sinks/daily_file_sink.h index e122f10f..65ab24f8 100644 --- a/include/spdlog/sinks/daily_file_sink.h +++ b/include/spdlog/sinks/daily_file_sink.h @@ -70,8 +70,9 @@ public: } } - const filename_t &filename() const + const filename_t &filename() { + std::lock_guard lock(base_sink::mutex_); return file_helper_.filename(); } diff --git a/include/spdlog/sinks/rotating_file_sink-inl.h b/include/spdlog/sinks/rotating_file_sink-inl.h index bd2d175d..0d27f057 100644 --- a/include/spdlog/sinks/rotating_file_sink-inl.h +++ b/include/spdlog/sinks/rotating_file_sink-inl.h @@ -54,8 +54,9 @@ SPDLOG_INLINE filename_t rotating_file_sink::calc_filename(const filename } template -SPDLOG_INLINE const filename_t &rotating_file_sink::filename() const +SPDLOG_INLINE const filename_t &rotating_file_sink::filename() { + std::lock_guard lock(base_sink::mutex_); return file_helper_.filename(); } diff --git a/include/spdlog/sinks/rotating_file_sink.h b/include/spdlog/sinks/rotating_file_sink.h index 5be8583a..e306dd9b 100644 --- a/include/spdlog/sinks/rotating_file_sink.h +++ b/include/spdlog/sinks/rotating_file_sink.h @@ -24,7 +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); - const filename_t &filename() const; + const filename_t &filename(); protected: void sink_it_(const details::log_msg &msg) override;