1
0
mirror of https://github.com/gabime/spdlog.git synced 2025-01-15 17:27:57 +00:00

Compare commits

...

9 Commits

Author SHA1 Message Date
Gabi Melman
0f42744f5c
Update rotating_file_sink-inl.h 2020-02-12 12:11:03 +02:00
Gabi Melman
e8daf7c73b
Merge pull request #1431 from tt4g/avoid-references-to-race-data-filename
Avoid references to race data filename
2020-02-12 12:09:25 +02:00
tt4g
0cf1af5bbf Avoid references to race data filename 2020-02-12 16:30:44 +09:00
Gabi Melman
a343328a21
Update rotating_file_sink-inl.h 2020-02-12 08:56:24 +02:00
Gabi Melman
53a56b82af
Update rotating_file_sink-inl.h 2020-02-12 07:51:42 +02:00
Gabi Melman
64dd4dc219
Update rotating_file_sink-inl.h 2020-02-12 07:49:29 +02:00
Gabi Melman
9e9da42c64
Update rotating_file_sink.h 2020-02-12 07:48:41 +02:00
Gabi Melman
5c410f4ca2
Merge pull request #1430 from tt4g/add-critical-section-to-filename-api
Add critical section to filename function of  each file sink
2020-02-12 07:35:52 +02:00
tt4g
0778211116 Add critical section to filename function of each file sink 2020-02-12 11:01:35 +09:00
3 changed files with 10 additions and 8 deletions

View File

@ -70,8 +70,9 @@ public:
}
}
const filename_t &filename() const
filename_t filename()
{
std::lock_guard<Mutex> lock(base_sink<Mutex>::mutex_);
return file_helper_.filename();
}

View File

@ -54,8 +54,9 @@ SPDLOG_INLINE filename_t rotating_file_sink<Mutex>::calc_filename(const filename
}
template<typename Mutex>
SPDLOG_INLINE const filename_t &rotating_file_sink<Mutex>::filename() const
SPDLOG_INLINE filename_t rotating_file_sink<Mutex>::filename()
{
std::lock_guard<Mutex> lock(base_sink<Mutex>::mutex_);
return file_helper_.filename();
}
@ -99,13 +100,13 @@ SPDLOG_INLINE void rotating_file_sink<Mutex>::rotate_()
}
filename_t target = calc_filename(base_filename_, i);
if (!rename_file(src, target))
if (!rename_file_(src, target))
{
// if failed try again after a small delay.
// this is a workaround to a windows issue, where very high rotation
// rates can cause the rename to fail with permission denied (because of antivirus?).
details::os::sleep_for_millis(100);
if (!rename_file(src, target))
if (!rename_file_(src, target))
{
file_helper_.reopen(true); // truncate the log file anyway to prevent it to grow beyond its limit!
current_size_ = 0;
@ -120,7 +121,7 @@ SPDLOG_INLINE void rotating_file_sink<Mutex>::rotate_()
// delete the target if exists, and rename the src file to target
// return true on success, false otherwise.
template<typename Mutex>
SPDLOG_INLINE bool rotating_file_sink<Mutex>::rename_file(const filename_t &src_filename, const filename_t &target_filename)
SPDLOG_INLINE bool rotating_file_sink<Mutex>::rename_file_(const filename_t &src_filename, const filename_t &target_filename)
{
// try to delete the target file in case it already exists.
(void)details::os::remove(target_filename);

View File

@ -24,7 +24,7 @@ class rotating_file_sink final : public base_sink<Mutex>
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;
filename_t filename();
protected:
void sink_it_(const details::log_msg &msg) override;
@ -40,7 +40,7 @@ private:
// delete the target if exists, and rename the src file to target
// return true on success, false otherwise.
bool rename_file(const filename_t &src_filename, const filename_t &target_filename);
bool rename_file_(const filename_t &src_filename, const filename_t &target_filename);
filename_t base_filename_;
std::size_t max_size_;
@ -75,4 +75,4 @@ inline std::shared_ptr<logger> rotating_logger_st(
#ifdef SPDLOG_HEADER_ONLY
#include "rotating_file_sink-inl.h"
#endif
#endif