Skip to content
This repository was archived by the owner on Jun 30, 2025. It is now read-only.

Commit 71a04a1

Browse files
committed
fixed-islogfromcurrentproject func
1 parent 489d35e commit 71a04a1

File tree

3 files changed

+13
-10
lines changed

3 files changed

+13
-10
lines changed

src/cleanup_immediately_unittest.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ TEST(CleanImmediately, logging) {
6060
google::EnableLogCleaner(0h);
6161

6262
for (unsigned i = 0; i < 1000; ++i) {
63-
LOG(INFO) << "cleanup test";
63+
LOG(WARNING) << "cleanup test";
6464
}
6565

6666
google::DisableLogCleaner();

src/cleanup_with_relative_prefix_unittest.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ TEST(CleanImmediatelyWithRelativePrefix, logging) {
6161
google::SetLogDestination(GLOG_INFO, "test_subdir/test_cleanup_");
6262

6363
for (unsigned i = 0; i < 1000; ++i) {
64-
LOG(INFO) << "cleanup test";
64+
LOG(ERROR) << "cleanup test";
6565
}
6666

6767
google::DisableLogCleaner();

src/logging.cc

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -446,6 +446,9 @@ class LogCleaner {
446446

447447
bool enabled() const { return enabled_; }
448448

449+
std::chrono::system_clock::time_point
450+
next_cleanup_time; // cycle count at which to clean overdue log
451+
449452
private:
450453
vector<string> GetOverdueLogNames(
451454
string log_directory,
@@ -463,8 +466,6 @@ class LogCleaner {
463466
bool enabled_{false};
464467
std::chrono::minutes overdue_{
465468
std::chrono::duration<int, std::ratio<kSecondsInWeek>>{1}};
466-
std::chrono::system_clock::time_point
467-
next_cleanup_time_; // cycle count at which to clean overdue log
468469
};
469470

470471
LogCleaner log_cleaner;
@@ -855,6 +856,13 @@ inline void LogDestination::LogToAllLogfiles(
855856
LogDestination::MaybeLogToLogfile(static_cast<LogSeverity>(i), timestamp,
856857
message, len);
857858
}
859+
860+
// avoid scanning logs too frequently
861+
if (timestamp >= log_cleaner.next_cleanup_time) {
862+
log_cleaner.next_cleanup_time = timestamp +
863+
std::chrono::duration_cast<std::chrono::system_clock::duration>(
864+
std::chrono::duration<int32>{FLAGS_logcleansecs}); // set next cleanup time
865+
}
858866
}
859867
}
860868

@@ -1317,15 +1325,10 @@ void LogCleaner::Run(const std::chrono::system_clock::time_point& current_time,
13171325
assert(!base_filename_selected || !base_filename.empty());
13181326

13191327
// avoid scanning logs too frequently
1320-
if (current_time < next_cleanup_time_) {
1328+
if (current_time < next_cleanup_time) {
13211329
return;
13221330
}
13231331

1324-
next_cleanup_time_ =
1325-
current_time +
1326-
std::chrono::duration_cast<std::chrono::system_clock::duration>(
1327-
std::chrono::duration<int32>{FLAGS_logcleansecs});
1328-
13291332
vector<string> dirs;
13301333

13311334
if (!base_filename_selected) {

0 commit comments

Comments
 (0)