Skip to content

Commit

Permalink
Rename LogInterface::rotate to after_rotation.
Browse files Browse the repository at this point in the history
  • Loading branch information
levlam committed May 17, 2021
1 parent fdeaafa commit 8231c58
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 23 deletions.
6 changes: 3 additions & 3 deletions tdutils/td/utils/CombinedLog.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}

Expand Down
8 changes: 4 additions & 4 deletions tdutils/td/utils/FileLog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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());
Expand Down
4 changes: 2 additions & 2 deletions tdutils/td/utils/FileLog.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class FileLog : public LogInterface {

bool get_redirect_stderr() const;

void rotate() final;
void after_rotation() final;

void lazy_rotate();

Expand All @@ -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
16 changes: 8 additions & 8 deletions tdutils/td/utils/TsFileLog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<string> get_file_paths() final {
vector<string> res;
for (auto &log : logs_) {
Expand Down
8 changes: 3 additions & 5 deletions tdutils/td/utils/logging.h
Original file line number Diff line number Diff line change
Expand Up @@ -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_

Expand Down Expand Up @@ -169,7 +167,7 @@ class LogInterface {

void append(int log_level, CSlice slice);

virtual void rotate() {
virtual void after_rotation() {
}

virtual vector<string> get_file_paths() {
Expand Down Expand Up @@ -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<string> get_file_paths() final {
Expand Down
2 changes: 1 addition & 1 deletion tdutils/test/log.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 8231c58

Please sign in to comment.