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

Commit 6ea4aea

Browse files
committed
fixed-islogfromcurrentproject func
1 parent 489d35e commit 6ea4aea

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

src/cleanup_immediately_unittest.cc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,8 @@ TEST(CleanImmediately, logging) {
6161

6262
for (unsigned i = 0; i < 1000; ++i) {
6363
LOG(INFO) << "cleanup test";
64+
LOG(WARNING) << "cleanup test";
65+
LOG(ERROR) << "cleanup test";
6466
}
6567

6668
google::DisableLogCleaner();

src/logging.cc

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1416,8 +1416,30 @@ bool LogCleaner::IsLogFromCurrentProject(
14161416
}
14171417
}
14181418

1419+
// As we want to delete old logs despite their severity,
1420+
// we need to replace <severity> in cleaned_base_file and find matching one.
1421+
const string::size_type dot_pos =
1422+
cleaned_base_filename.find_last_of('.', cleaned_base_filename.size() - 2);
1423+
1424+
const string new_base_filename = cleaned_base_filename.substr(0, dot_pos + 1);
1425+
1426+
// Loop through severity names and check whether
1427+
// filepath contains cleaned_base_filename_with_severity
1428+
bool found_file = false;
1429+
for (const auto& severity : LogSeverityNames) {
1430+
string cleaned_base_filename_with_severity = new_base_filename + severity;
1431+
1432+
if (filepath.find(cleaned_base_filename_with_severity) == 0) {
1433+
// Assign cleaned_base_filename to our new base name
1434+
// Add trailing dot we deleted earlier
1435+
cleaned_base_filename = cleaned_base_filename_with_severity + '.';
1436+
found_file = true;
1437+
break;
1438+
}
1439+
}
1440+
14191441
// Return early if the filename doesn't start with `cleaned_base_filename`.
1420-
if (filepath.find(cleaned_base_filename) != 0) {
1442+
if (!found_file) {
14211443
return false;
14221444
}
14231445

0 commit comments

Comments
 (0)