Skip to content

Commit

Permalink
fixed-islogfromcurrentproject func
Browse files Browse the repository at this point in the history
  • Loading branch information
Mivekk committed Jan 16, 2024
1 parent 489d35e commit 6ea4aea
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
2 changes: 2 additions & 0 deletions src/cleanup_immediately_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ TEST(CleanImmediately, logging) {

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

google::DisableLogCleaner();
Expand Down
24 changes: 23 additions & 1 deletion src/logging.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1416,8 +1416,30 @@ bool LogCleaner::IsLogFromCurrentProject(
}
}

// As we want to delete old logs despite their severity,
// we need to replace <severity> in cleaned_base_file and find matching one.
const string::size_type dot_pos =
cleaned_base_filename.find_last_of('.', cleaned_base_filename.size() - 2);

const string new_base_filename = cleaned_base_filename.substr(0, dot_pos + 1);

// Loop through severity names and check whether
// filepath contains cleaned_base_filename_with_severity
bool found_file = false;
for (const auto& severity : LogSeverityNames) {
string cleaned_base_filename_with_severity = new_base_filename + severity;

if (filepath.find(cleaned_base_filename_with_severity) == 0) {
// Assign cleaned_base_filename to our new base name
// Add trailing dot we deleted earlier
cleaned_base_filename = cleaned_base_filename_with_severity + '.';
found_file = true;
break;
}
}

// Return early if the filename doesn't start with `cleaned_base_filename`.
if (filepath.find(cleaned_base_filename) != 0) {
if (!found_file) {
return false;
}

Expand Down

0 comments on commit 6ea4aea

Please sign in to comment.