diff --git a/tdutils/td/utils/CombinedLog.h b/tdutils/td/utils/CombinedLog.h index 9f48b886a..87a690e77 100644 --- a/tdutils/td/utils/CombinedLog.h +++ b/tdutils/td/utils/CombinedLog.h @@ -62,12 +62,12 @@ class CombinedLog : public LogInterface { } } - void rotate() final { + void after_rotation() final { if (first_) { - first_->rotate(); + first_->after_rotation(); } if (second_) { - second_->rotate(); + second_->after_rotation(); } } diff --git a/tdutils/td/utils/FileLog.cpp b/tdutils/td/utils/FileLog.cpp index c907f3d6e..23f1a257b 100644 --- a/tdutils/td/utils/FileLog.cpp +++ b/tdutils/td/utils/FileLog.cpp @@ -76,7 +76,7 @@ void FileLog::do_append(int log_level, CSlice slice) { if (status.is_error()) { process_fatal_error(PSLICE() << status.error() << " in " << __FILE__ << " at " << __LINE__); } - do_rotate(); + do_after_rotation(); } while (!slice.empty()) { auto r_size = fd_.write(slice); @@ -89,18 +89,18 @@ void FileLog::do_append(int log_level, CSlice slice) { } } -void FileLog::rotate() { +void FileLog::after_rotation() { if (path_.empty()) { return; } - do_rotate(); + do_after_rotation(); } void FileLog::lazy_rotate() { want_rotate_ = true; } -void FileLog::do_rotate() { +void FileLog::do_after_rotation() { want_rotate_ = false; ScopedDisableLog disable_log; // to ensure that nothing will be printed to the closed log CHECK(!path_.empty()); diff --git a/tdutils/td/utils/FileLog.h b/tdutils/td/utils/FileLog.h index a057fc7b3..b57434f0c 100644 --- a/tdutils/td/utils/FileLog.h +++ b/tdutils/td/utils/FileLog.h @@ -34,7 +34,7 @@ class FileLog : public LogInterface { bool get_redirect_stderr() const; - void rotate() final; + void after_rotation() final; void lazy_rotate(); @@ -48,7 +48,7 @@ class FileLog : public LogInterface { void do_append(int log_level, CSlice slice) final; - void do_rotate(); + void do_after_rotation(); }; } // namespace td diff --git a/tdutils/td/utils/TsFileLog.cpp b/tdutils/td/utils/TsFileLog.cpp index c4095af1d..e904b5dd7 100644 --- a/tdutils/td/utils/TsFileLog.cpp +++ b/tdutils/td/utils/TsFileLog.cpp @@ -33,6 +33,14 @@ class TsFileLog : public LogInterface { return init_info(&logs_[0]); } + void rotate() { + for (auto &info : logs_) { + if (info.is_inited.load(std::memory_order_acquire)) { + info.log.lazy_rotate(); + } + } + } + private: struct Info { FileLog log; @@ -79,14 +87,6 @@ class TsFileLog : public LogInterface { get_current_logger()->do_append(log_level, slice); } - void rotate() final { - for (auto &info : logs_) { - if (info.is_inited.load(std::memory_order_acquire)) { - info.log.lazy_rotate(); - } - } - } - vector get_file_paths() final { vector res; for (auto &log : logs_) { diff --git a/tdutils/td/utils/logging.h b/tdutils/td/utils/logging.h index 528186aa8..68031cfb1 100644 --- a/tdutils/td/utils/logging.h +++ b/tdutils/td/utils/logging.h @@ -59,8 +59,6 @@ #define VLOG(level) LOG_IMPL(DEBUG, level, true, TD_DEFINE_STR(level)) #define VLOG_IF(level, condition) LOG_IMPL(DEBUG, level, condition, TD_DEFINE_STR(level) " " #condition) -#define LOG_ROTATE() ::td::log_interface->rotate() - #define LOG_TAG ::td::Logger::tag_ #define LOG_TAG2 ::td::Logger::tag2_ @@ -169,7 +167,7 @@ class LogInterface { void append(int log_level, CSlice slice); - virtual void rotate() { + virtual void after_rotation() { } virtual vector get_file_paths() { @@ -278,9 +276,9 @@ class TsLog : public LogInterface { log_ = log; exit_critical(); } - void rotate() final { + void after_rotation() final { enter_critical(); - log_->rotate(); + log_->after_rotation(); exit_critical(); } vector get_file_paths() final { diff --git a/tdutils/test/log.cpp b/tdutils/test/log.cpp index b76f6c2bc..078ddf860 100644 --- a/tdutils/test/log.cpp +++ b/tdutils/test/log.cpp @@ -64,7 +64,7 @@ class LogBenchmark : public td::Benchmark { auto str = PSTRING() << "#" << n << " : fsjklfdjsklfjdsklfjdksl\n"; for (int i = 0; i < n; i++) { if (i % 10000 == 0) { - log_->rotate(); + log_->after_rotation(); } if (test_full_logging_) { LOG(ERROR) << str;