summaryrefslogtreecommitdiffstats
path: root/Lib/logging
diff options
context:
space:
mode:
authorGabriele Catania <gabriele.ctn@gmail.com>2024-02-21 21:09:06 (GMT)
committerGitHub <noreply@github.com>2024-02-21 21:09:06 (GMT)
commit113687a8381d6dde179aeede607bcbca5c09d182 (patch)
treed95fab0e18bb2b560cb941f3541c426b21b75605 /Lib/logging
parent347acded845d07b70232cade8d576b6f0aaeb473 (diff)
downloadcpython-113687a8381d6dde179aeede607bcbca5c09d182.zip
cpython-113687a8381d6dde179aeede607bcbca5c09d182.tar.gz
cpython-113687a8381d6dde179aeede607bcbca5c09d182.tar.bz2
gh-93205: When rotating logs with no namer specified, match whole extension (GH-93224)
Diffstat (limited to 'Lib/logging')
-rw-r--r--Lib/logging/handlers.py43
1 files changed, 24 insertions, 19 deletions
diff --git a/Lib/logging/handlers.py b/Lib/logging/handlers.py
index e7f1322..895f11c 100644
--- a/Lib/logging/handlers.py
+++ b/Lib/logging/handlers.py
@@ -369,16 +369,20 @@ class TimedRotatingFileHandler(BaseRotatingHandler):
dirName, baseName = os.path.split(self.baseFilename)
fileNames = os.listdir(dirName)
result = []
- # See bpo-44753: Don't use the extension when computing the prefix.
- n, e = os.path.splitext(baseName)
- prefix = n + '.'
- plen = len(prefix)
- for fileName in fileNames:
- if self.namer is None:
- # Our files will always start with baseName
- if not fileName.startswith(baseName):
- continue
- else:
+ if self.namer is None:
+ prefix = baseName + '.'
+ plen = len(prefix)
+ for fileName in fileNames:
+ if fileName[:plen] == prefix:
+ suffix = fileName[plen:]
+ if self.extMatch.match(suffix):
+ result.append(os.path.join(dirName, fileName))
+ else:
+ # See bpo-44753: Don't use the extension when computing the prefix.
+ n, e = os.path.splitext(baseName)
+ prefix = n + '.'
+ plen = len(prefix)
+ for fileName in fileNames:
# Our files could be just about anything after custom naming, but
# likely candidates are of the form
# foo.log.DATETIME_SUFFIX or foo.DATETIME_SUFFIX.log
@@ -386,15 +390,16 @@ class TimedRotatingFileHandler(BaseRotatingHandler):
len(fileName) > (plen + 1) and not fileName[plen+1].isdigit()):
continue
- if fileName[:plen] == prefix:
- suffix = fileName[plen:]
- # See bpo-45628: The date/time suffix could be anywhere in the
- # filename
- parts = suffix.split('.')
- for part in parts:
- if self.extMatch.match(part):
- result.append(os.path.join(dirName, fileName))
- break
+ if fileName[:plen] == prefix:
+ suffix = fileName[plen:]
+ # See bpo-45628: The date/time suffix could be anywhere in the
+ # filename
+
+ parts = suffix.split('.')
+ for part in parts:
+ if self.extMatch.match(part):
+ result.append(os.path.join(dirName, fileName))
+ break
if len(result) < self.backupCount:
result = []
else: