summaryrefslogtreecommitdiffstats
path: root/contrib/tools/python3/Lib/logging
diff options
context:
space:
mode:
authorshadchin <[email protected]>2024-04-28 21:17:44 +0300
committershadchin <[email protected]>2024-04-28 21:25:54 +0300
commita55d99a3eb72f90355bc146baeda18aa7eb97352 (patch)
treeb17cfed786effe8b81bba022239d6729f716fbeb /contrib/tools/python3/Lib/logging
parent67bf49d08acf1277eff4c336021ac22d964bb4c4 (diff)
Update Python 3 to 3.12.3
7d09de7d8b99ea2be554ef0fc61276942ca9c2e1
Diffstat (limited to 'contrib/tools/python3/Lib/logging')
-rw-r--r--contrib/tools/python3/Lib/logging/__init__.py25
-rw-r--r--contrib/tools/python3/Lib/logging/handlers.py116
2 files changed, 65 insertions, 76 deletions
diff --git a/contrib/tools/python3/Lib/logging/__init__.py b/contrib/tools/python3/Lib/logging/__init__.py
index 056380fb228..22d31983323 100644
--- a/contrib/tools/python3/Lib/logging/__init__.py
+++ b/contrib/tools/python3/Lib/logging/__init__.py
@@ -1521,7 +1521,7 @@ class Logger(Filterer):
To pass exception information, use the keyword argument exc_info with
a true value, e.g.
- logger.debug("Houston, we have a %s", "thorny problem", exc_info=1)
+ logger.debug("Houston, we have a %s", "thorny problem", exc_info=True)
"""
if self.isEnabledFor(DEBUG):
self._log(DEBUG, msg, args, **kwargs)
@@ -1533,7 +1533,7 @@ class Logger(Filterer):
To pass exception information, use the keyword argument exc_info with
a true value, e.g.
- logger.info("Houston, we have a %s", "notable problem", exc_info=1)
+ logger.info("Houston, we have a %s", "notable problem", exc_info=True)
"""
if self.isEnabledFor(INFO):
self._log(INFO, msg, args, **kwargs)
@@ -1545,7 +1545,7 @@ class Logger(Filterer):
To pass exception information, use the keyword argument exc_info with
a true value, e.g.
- logger.warning("Houston, we have a %s", "bit of a problem", exc_info=1)
+ logger.warning("Houston, we have a %s", "bit of a problem", exc_info=True)
"""
if self.isEnabledFor(WARNING):
self._log(WARNING, msg, args, **kwargs)
@@ -1562,7 +1562,7 @@ class Logger(Filterer):
To pass exception information, use the keyword argument exc_info with
a true value, e.g.
- logger.error("Houston, we have a %s", "major problem", exc_info=1)
+ logger.error("Houston, we have a %s", "major problem", exc_info=True)
"""
if self.isEnabledFor(ERROR):
self._log(ERROR, msg, args, **kwargs)
@@ -1580,7 +1580,7 @@ class Logger(Filterer):
To pass exception information, use the keyword argument exc_info with
a true value, e.g.
- logger.critical("Houston, we have a %s", "major disaster", exc_info=1)
+ logger.critical("Houston, we have a %s", "major disaster", exc_info=True)
"""
if self.isEnabledFor(CRITICAL):
self._log(CRITICAL, msg, args, **kwargs)
@@ -1598,7 +1598,7 @@ class Logger(Filterer):
To pass exception information, use the keyword argument exc_info with
a true value, e.g.
- logger.log(level, "We have a %s", "mysterious problem", exc_info=1)
+ logger.log(level, "We have a %s", "mysterious problem", exc_info=True)
"""
if not isinstance(level, int):
if raiseExceptions:
@@ -1985,18 +1985,11 @@ class LoggerAdapter(object):
"""
return self.logger.hasHandlers()
- def _log(self, level, msg, args, exc_info=None, extra=None, stack_info=False):
+ def _log(self, level, msg, args, **kwargs):
"""
Low-level log implementation, proxied to allow nested logger adapters.
"""
- return self.logger._log(
- level,
- msg,
- args,
- exc_info=exc_info,
- extra=extra,
- stack_info=stack_info,
- )
+ return self.logger._log(level, msg, args, **kwargs)
@property
def manager(self):
@@ -2056,7 +2049,7 @@ def basicConfig(**kwargs):
that this argument is incompatible with 'filename' - if both
are present, 'stream' is ignored.
handlers If specified, this should be an iterable of already created
- handlers, which will be added to the root handler. Any handler
+ handlers, which will be added to the root logger. Any handler
in the list which does not have a formatter assigned will be
assigned the formatter created in this function.
force If this keyword is specified as true, any existing handlers
diff --git a/contrib/tools/python3/Lib/logging/handlers.py b/contrib/tools/python3/Lib/logging/handlers.py
index 6e88184b512..1ae6bb84434 100644
--- a/contrib/tools/python3/Lib/logging/handlers.py
+++ b/contrib/tools/python3/Lib/logging/handlers.py
@@ -232,19 +232,19 @@ class TimedRotatingFileHandler(BaseRotatingHandler):
if self.when == 'S':
self.interval = 1 # one second
self.suffix = "%Y-%m-%d_%H-%M-%S"
- self.extMatch = r"^\d{4}-\d{2}-\d{2}_\d{2}-\d{2}-\d{2}(\.\w+)?$"
+ extMatch = r"(?<!\d)\d{4}-\d{2}-\d{2}_\d{2}-\d{2}-\d{2}(?!\d)"
elif self.when == 'M':
self.interval = 60 # one minute
self.suffix = "%Y-%m-%d_%H-%M"
- self.extMatch = r"^\d{4}-\d{2}-\d{2}_\d{2}-\d{2}(\.\w+)?$"
+ extMatch = r"(?<!\d)\d{4}-\d{2}-\d{2}_\d{2}-\d{2}(?!\d)"
elif self.when == 'H':
self.interval = 60 * 60 # one hour
self.suffix = "%Y-%m-%d_%H"
- self.extMatch = r"^\d{4}-\d{2}-\d{2}_\d{2}(\.\w+)?$"
+ extMatch = r"(?<!\d)\d{4}-\d{2}-\d{2}_\d{2}(?!\d)"
elif self.when == 'D' or self.when == 'MIDNIGHT':
self.interval = 60 * 60 * 24 # one day
self.suffix = "%Y-%m-%d"
- self.extMatch = r"^\d{4}-\d{2}-\d{2}(\.\w+)?$"
+ extMatch = r"(?<!\d)\d{4}-\d{2}-\d{2}(?!\d)"
elif self.when.startswith('W'):
self.interval = 60 * 60 * 24 * 7 # one week
if len(self.when) != 2:
@@ -253,11 +253,17 @@ class TimedRotatingFileHandler(BaseRotatingHandler):
raise ValueError("Invalid day specified for weekly rollover: %s" % self.when)
self.dayOfWeek = int(self.when[1])
self.suffix = "%Y-%m-%d"
- self.extMatch = r"^\d{4}-\d{2}-\d{2}(\.\w+)?$"
+ extMatch = r"(?<!\d)\d{4}-\d{2}-\d{2}(?!\d)"
else:
raise ValueError("Invalid rollover interval specified: %s" % self.when)
- self.extMatch = re.compile(self.extMatch, re.ASCII)
+ # extMatch is a pattern for matching a datetime suffix in a file name.
+ # After custom naming, it is no longer guaranteed to be separated by
+ # periods from other parts of the filename. The lookup statements
+ # (?<!\d) and (?!\d) ensure that the datetime suffix (which itself
+ # starts and ends with digits) is not preceded or followed by digits.
+ # This reduces the number of false matches and improves performance.
+ self.extMatch = re.compile(extMatch, re.ASCII)
self.interval = self.interval * interval # multiply by units requested
# The following line added because the filename passed in could be a
# path object (see Issue #27493), but self.baseFilename will be a string
@@ -299,7 +305,7 @@ class TimedRotatingFileHandler(BaseRotatingHandler):
r = rotate_ts - ((currentHour * 60 + currentMinute) * 60 +
currentSecond)
- if r < 0:
+ if r <= 0:
# Rotate time is before the current time (for example when
# self.rotateAt is 13:45 and it now 14:15), rotation is
# tomorrow.
@@ -328,17 +334,21 @@ class TimedRotatingFileHandler(BaseRotatingHandler):
daysToWait = self.dayOfWeek - day
else:
daysToWait = 6 - day + self.dayOfWeek + 1
- newRolloverAt = result + (daysToWait * (60 * 60 * 24))
- if not self.utc:
- dstNow = t[-1]
- dstAtRollover = time.localtime(newRolloverAt)[-1]
- if dstNow != dstAtRollover:
- if not dstNow: # DST kicks in before next rollover, so we need to deduct an hour
- addend = -3600
- else: # DST bows out before next rollover, so we need to add an hour
- addend = 3600
- newRolloverAt += addend
- result = newRolloverAt
+ result += daysToWait * _MIDNIGHT
+ result += self.interval - _MIDNIGHT * 7
+ else:
+ result += self.interval - _MIDNIGHT
+ if not self.utc:
+ dstNow = t[-1]
+ dstAtRollover = time.localtime(result)[-1]
+ if dstNow != dstAtRollover:
+ if not dstNow: # DST kicks in before next rollover, so we need to deduct an hour
+ addend = -3600
+ if not time.localtime(result-3600)[-1]:
+ addend = 0
+ else: # DST bows out before next rollover, so we need to add an hour
+ addend = 3600
+ result += addend
return result
def shouldRollover(self, record):
@@ -369,32 +379,28 @@ 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:
- # 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
- # filename
- parts = suffix.split('.')
- for part in parts:
- if self.extMatch.match(part):
+ if self.namer is None:
+ prefix = baseName + '.'
+ plen = len(prefix)
+ for fileName in fileNames:
+ if fileName[:plen] == prefix:
+ suffix = fileName[plen:]
+ if self.extMatch.fullmatch(suffix):
+ result.append(os.path.join(dirName, fileName))
+ else:
+ for fileName in fileNames:
+ # Our files could be just about anything after custom naming,
+ # but they should contain the datetime suffix.
+ # Try to find the datetime suffix in the file name and verify
+ # that the file name can be generated by this handler.
+ m = self.extMatch.search(fileName)
+ while m:
+ dfn = self.namer(self.baseFilename + "." + m[0])
+ if os.path.basename(dfn) == fileName:
result.append(os.path.join(dirName, fileName))
break
+ m = self.extMatch.search(fileName, m.start() + 1)
+
if len(result) < self.backupCount:
result = []
else:
@@ -410,17 +416,14 @@ class TimedRotatingFileHandler(BaseRotatingHandler):
then we have to get a list of matching filenames, sort them and remove
the one with the oldest suffix.
"""
- if self.stream:
- self.stream.close()
- self.stream = None
# get the time that this sequence started at and make it a TimeTuple
currentTime = int(time.time())
- dstNow = time.localtime(currentTime)[-1]
t = self.rolloverAt - self.interval
if self.utc:
timeTuple = time.gmtime(t)
else:
timeTuple = time.localtime(t)
+ dstNow = time.localtime(currentTime)[-1]
dstThen = timeTuple[-1]
if dstNow != dstThen:
if dstNow:
@@ -431,26 +434,19 @@ class TimedRotatingFileHandler(BaseRotatingHandler):
dfn = self.rotation_filename(self.baseFilename + "." +
time.strftime(self.suffix, timeTuple))
if os.path.exists(dfn):
- os.remove(dfn)
+ # Already rolled over.
+ return
+
+ if self.stream:
+ self.stream.close()
+ self.stream = None
self.rotate(self.baseFilename, dfn)
if self.backupCount > 0:
for s in self.getFilesToDelete():
os.remove(s)
if not self.delay:
self.stream = self._open()
- newRolloverAt = self.computeRollover(currentTime)
- while newRolloverAt <= currentTime:
- newRolloverAt = newRolloverAt + self.interval
- #If DST changes and midnight or weekly rollover, adjust for this.
- if (self.when == 'MIDNIGHT' or self.when.startswith('W')) and not self.utc:
- dstAtRollover = time.localtime(newRolloverAt)[-1]
- if dstNow != dstAtRollover:
- if not dstNow: # DST kicks in before next rollover, so we need to deduct an hour
- addend = -3600
- else: # DST bows out before next rollover, so we need to add an hour
- addend = 3600
- newRolloverAt += addend
- self.rolloverAt = newRolloverAt
+ self.rolloverAt = self.computeRollover(currentTime)
class WatchedFileHandler(logging.FileHandler):
"""