mirror of
https://github.com/gabime/spdlog.git
synced 2024-11-15 16:35:45 +08:00
Fix #2261
This commit is contained in:
parent
5afff7821f
commit
7536192058
@ -67,13 +67,18 @@ SPDLOG_INLINE void rotating_file_sink<Mutex>::sink_it_(const details::log_msg &m
|
|||||||
{
|
{
|
||||||
memory_buf_t formatted;
|
memory_buf_t formatted;
|
||||||
base_sink<Mutex>::formatter_->format(msg, formatted);
|
base_sink<Mutex>::formatter_->format(msg, formatted);
|
||||||
current_size_ += formatted.size();
|
auto new_size = current_size_ + formatted.size();
|
||||||
if (current_size_ > max_size_)
|
|
||||||
|
// rotate if the new estimated file size exceeds max size.
|
||||||
|
// check also that the real size > 0 to better deal with full disk (see issue #2261).
|
||||||
|
// we only check the real size when new_size > max_size_ because it is relatively expensive.
|
||||||
|
if (new_size > max_size_ && file_helper_.size() > 0)
|
||||||
{
|
{
|
||||||
rotate_();
|
rotate_();
|
||||||
current_size_ = formatted.size();
|
new_size = formatted.size();
|
||||||
}
|
}
|
||||||
file_helper_.write(formatted);
|
file_helper_.write(formatted);
|
||||||
|
current_size_ = new_size;
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename Mutex>
|
template<typename Mutex>
|
||||||
@ -92,6 +97,7 @@ SPDLOG_INLINE void rotating_file_sink<Mutex>::rotate_()
|
|||||||
{
|
{
|
||||||
using details::os::filename_to_str;
|
using details::os::filename_to_str;
|
||||||
using details::os::path_exists;
|
using details::os::path_exists;
|
||||||
|
|
||||||
file_helper_.close();
|
file_helper_.close();
|
||||||
for (auto i = max_files_; i > 0; --i)
|
for (auto i = max_files_; i > 0; --i)
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user