mirror of
https://github.com/gabime/spdlog.git
synced 2025-01-15 17:27:57 +00:00
Compare commits
9 Commits
574563d711
...
0f42744f5c
Author | SHA1 | Date | |
---|---|---|---|
|
0f42744f5c | ||
|
e8daf7c73b | ||
|
0cf1af5bbf | ||
|
a343328a21 | ||
|
53a56b82af | ||
|
64dd4dc219 | ||
|
9e9da42c64 | ||
|
5c410f4ca2 | ||
|
0778211116 |
@ -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();
|
||||
}
|
||||
|
||||
|
@ -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);
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user