diff --git a/src/logging.cc b/src/logging.cc index 14385eb0a..a21a53164 100644 --- a/src/logging.cc +++ b/src/logging.cc @@ -1416,8 +1416,30 @@ bool LogCleaner::IsLogFromCurrentProject( } } + // As we want to delete old logs despite their severity, + // we need to replace in cleaned_base_file and find matching one. + const string::size_type dot_pos = + cleaned_base_filename.find_last_of('.', cleaned_base_filename.size() - 1); + + const string new_base_filename = cleaned_base_filename.substr(0, dot_pos); + + // 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; }