@@ -446,6 +446,9 @@ class LogCleaner {
446
446
447
447
bool enabled () const { return enabled_; }
448
448
449
+ std::chrono::system_clock::time_point
450
+ next_cleanup_time; // cycle count at which to clean overdue log
451
+
449
452
private:
450
453
vector<string> GetOverdueLogNames (
451
454
string log_directory,
@@ -463,8 +466,6 @@ class LogCleaner {
463
466
bool enabled_{false };
464
467
std::chrono::minutes overdue_{
465
468
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
468
469
};
469
470
470
471
LogCleaner log_cleaner;
@@ -855,6 +856,13 @@ inline void LogDestination::LogToAllLogfiles(
855
856
LogDestination::MaybeLogToLogfile (static_cast <LogSeverity>(i), timestamp,
856
857
message, len);
857
858
}
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
+ }
858
866
}
859
867
}
860
868
@@ -1317,15 +1325,10 @@ void LogCleaner::Run(const std::chrono::system_clock::time_point& current_time,
1317
1325
assert (!base_filename_selected || !base_filename.empty ());
1318
1326
1319
1327
// avoid scanning logs too frequently
1320
- if (current_time < next_cleanup_time_ ) {
1328
+ if (current_time < next_cleanup_time ) {
1321
1329
return ;
1322
1330
}
1323
1331
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
-
1329
1332
vector<string> dirs;
1330
1333
1331
1334
if (!base_filename_selected) {
0 commit comments