Adding on demand truncation for basic file sinks (#3280)

* Adding support to truncate on demand for basic file sink

* Remove unnecessary file close

* Adding lock in basic_file_sink truncate()
This commit is contained in:
Matteo Del Seppia
2024-12-03 00:38:51 +01:00
committed by GitHub
parent 1e6250e183
commit 65e388e82b
3 changed files with 27 additions and 0 deletions

View File

@@ -26,6 +26,12 @@ SPDLOG_INLINE const filename_t &basic_file_sink<Mutex>::filename() const {
return file_helper_.filename();
}
template <typename Mutex>
SPDLOG_INLINE void basic_file_sink<Mutex>::truncate() {
std::lock_guard<Mutex> lock(base_sink<Mutex>::mutex_);
file_helper_.reopen(true);
}
template <typename Mutex>
SPDLOG_INLINE void basic_file_sink<Mutex>::sink_it_(const details::log_msg &msg) {
memory_buf_t formatted;

View File

@@ -23,6 +23,7 @@ public:
bool truncate = false,
const file_event_handlers &event_handlers = {});
const filename_t &filename() const;
void truncate();
protected:
void sink_it_(const details::log_msg &msg) override;