getLogFileIndex method
Get the index of the log file from the fileName
.
Returns the log file index int or 0 if index not founded.
Implementation
@visibleForTesting
int getLogFileIndex(final String fileName) {
final int logSuffixIndex = fileName.lastIndexOf(logFileNameSuffix);
if (logSuffixIndex < 0) {
// if the last index is less than 0 so we either have no log file or
// we have a log file that does not match the log file naming convention
// of this files handler. So in both these cases we start from 0.
return 0;
}
final RegExp pattern = RegExp(r'(\d)+$');
final String? foundIndex =
pattern.firstMatch(fileName.substring(logSuffixIndex))?.group(0);
return foundIndex != null ? int.tryParse(foundIndex) ?? 0 : 0;
}