Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/gabime/spdlog.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGabi Melman <gmelman1@gmail.com>2022-06-19 02:22:28 +0300
committerGitHub <noreply@github.com>2022-06-19 02:22:28 +0300
commit03315853dff2f749f9da720a646a6e9f73442bdb (patch)
treec9d2764f7a561094a648c512e06513cd307c663a /include
parent298a200f69d66114adde2d5d8ad34f2cce5a5b69 (diff)
parent1eafcfab70d0f99745572cd61f21d7ed87d98b18 (diff)
Merge pull request #2386 from panzhongxian/v1.x
Romove the empty file if no log in first period in hourly logger
Diffstat (limited to 'include')
-rw-r--r--include/spdlog/sinks/hourly_file_sink.h8
1 files changed, 8 insertions, 0 deletions
diff --git a/include/spdlog/sinks/hourly_file_sink.h b/include/spdlog/sinks/hourly_file_sink.h
index 029e7b1d..33dd8948 100644
--- a/include/spdlog/sinks/hourly_file_sink.h
+++ b/include/spdlog/sinks/hourly_file_sink.h
@@ -57,6 +57,7 @@ public:
auto now = log_clock::now();
auto filename = FileNameCalc::calc_filename(base_filename_, now_tm(now));
file_helper_.open(filename, truncate_);
+ remove_init_file_ = file_helper_.size() == 0;
rotation_tp_ = next_rotation_tp_();
if (max_files_ > 0)
@@ -78,10 +79,16 @@ protected:
bool should_rotate = time >= rotation_tp_;
if (should_rotate)
{
+ if (remove_init_file_)
+ {
+ file_helper_.close();
+ details::os::remove(file_helper_.filename());
+ }
auto filename = FileNameCalc::calc_filename(base_filename_, now_tm(time));
file_helper_.open(filename, truncate_);
rotation_tp_ = next_rotation_tp_();
}
+ remove_init_file_ = false;
memory_buf_t formatted;
base_sink<Mutex>::formatter_->format(msg, formatted);
file_helper_.write(formatted);
@@ -170,6 +177,7 @@ private:
bool truncate_;
uint16_t max_files_;
details::circular_q<filename_t> filenames_q_;
+ bool remove_init_file_;
};
using hourly_file_sink_mt = hourly_file_sink<std::mutex>;