summaryrefslogtreecommitdiffstats
path: root/Lib/logging
diff options
context:
space:
mode:
authorVinay Sajip <vinay_sajip@yahoo.co.uk>2021-12-14 00:53:37 (GMT)
committerGitHub <noreply@github.com>2021-12-14 00:53:37 (GMT)
commitcb589d1b6bad4b75852c2e2a471a3800d5efdca7 (patch)
tree8f740a9418027df57d63bdb1ee510afa8ec1d148 /Lib/logging
parenteb483c46d62707bdf705491f76cf1fa9642fb47e (diff)
downloadcpython-cb589d1b6bad4b75852c2e2a471a3800d5efdca7.zip
cpython-cb589d1b6bad4b75852c2e2a471a3800d5efdca7.tar.gz
cpython-cb589d1b6bad4b75852c2e2a471a3800d5efdca7.tar.bz2
bpo-46063: Improve algorithm for computing which rolled-over log fileā€¦ (GH-30093)
Diffstat (limited to 'Lib/logging')
-rw-r--r--Lib/logging/handlers.py19
1 files changed, 16 insertions, 3 deletions
diff --git a/Lib/logging/handlers.py b/Lib/logging/handlers.py
index d42c48d..78e919d 100644
--- a/Lib/logging/handlers.py
+++ b/Lib/logging/handlers.py
@@ -1,4 +1,4 @@
-# Copyright 2001-2016 by Vinay Sajip. All Rights Reserved.
+# Copyright 2001-2021 by Vinay Sajip. All Rights Reserved.
#
# Permission to use, copy, modify, and distribute this software and its
# documentation for any purpose and without fee is hereby granted,
@@ -18,7 +18,7 @@
Additional handlers for the logging package for Python. The core package is
based on PEP 282 and comments thereto in comp.lang.python.
-Copyright (C) 2001-2016 Vinay Sajip. All Rights Reserved.
+Copyright (C) 2001-2021 Vinay Sajip. All Rights Reserved.
To use, simply 'import logging.handlers' and log away!
"""
@@ -366,9 +366,22 @@ class TimedRotatingFileHandler(BaseRotatingHandler):
fileNames = os.listdir(dirName)
result = []
# See bpo-44753: Don't use the extension when computing the prefix.
- prefix = os.path.splitext(baseName)[0] + "."
+ 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:
+ # 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
+ if (not fileName.startswith(baseName) and fileName.endswith(e) and
+ 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