Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed IsLogFromCurrentProject to include all severities #1062

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/cleanup_immediately_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ TEST(CleanImmediately, logging) {
google::EnableLogCleaner(0h);

for (unsigned i = 0; i < 1000; ++i) {
LOG(INFO) << "cleanup test";
LOG(WARNING) << "cleanup test";
}

google::DisableLogCleaner();
Expand Down
2 changes: 1 addition & 1 deletion src/cleanup_with_relative_prefix_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ TEST(CleanImmediatelyWithRelativePrefix, logging) {
google::SetLogDestination(GLOG_INFO, "test_subdir/test_cleanup_");

for (unsigned i = 0; i < 1000; ++i) {
LOG(INFO) << "cleanup test";
LOG(ERROR) << "cleanup test";
}

google::DisableLogCleaner();
Expand Down
19 changes: 11 additions & 8 deletions src/logging.cc
Original file line number Diff line number Diff line change
Expand Up @@ -446,6 +446,9 @@ class LogCleaner {

bool enabled() const { return enabled_; }

std::chrono::system_clock::time_point
next_cleanup_time; // cycle count at which to clean overdue log

private:
vector<string> GetOverdueLogNames(
string log_directory,
Expand All @@ -463,8 +466,6 @@ class LogCleaner {
bool enabled_{false};
std::chrono::minutes overdue_{
std::chrono::duration<int, std::ratio<kSecondsInWeek>>{1}};
std::chrono::system_clock::time_point
next_cleanup_time_; // cycle count at which to clean overdue log
};

LogCleaner log_cleaner;
Expand Down Expand Up @@ -855,6 +856,13 @@ inline void LogDestination::LogToAllLogfiles(
LogDestination::MaybeLogToLogfile(static_cast<LogSeverity>(i), timestamp,
message, len);
}

// avoid scanning logs too frequently
if (timestamp >= log_cleaner.next_cleanup_time) {
log_cleaner.next_cleanup_time = timestamp +
std::chrono::duration_cast<std::chrono::system_clock::duration>(
std::chrono::duration<int32>{FLAGS_logcleansecs}); // set next cleanup time
}
}
}

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

// avoid scanning logs too frequently
if (current_time < next_cleanup_time_) {
if (current_time < next_cleanup_time) {
return;
}

next_cleanup_time_ =
current_time +
std::chrono::duration_cast<std::chrono::system_clock::duration>(
std::chrono::duration<int32>{FLAGS_logcleansecs});

vector<string> dirs;

if (!base_filename_selected) {
Expand Down
Loading