summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>2022-08-27 14:10:17 (GMT)
committerGitHub <noreply@github.com>2022-08-27 14:10:17 (GMT)
commitc0a9859afb522d555a9b9851be48be56327d252d (patch)
tree2514008208225d2ad34b39b5b8751cbbd9779adc /Lib
parenta2cf98449c8e176e8534eb961043f6eac918ce2b (diff)
downloadcpython-c0a9859afb522d555a9b9851be48be56327d252d.zip
cpython-c0a9859afb522d555a9b9851be48be56327d252d.tar.gz
cpython-c0a9859afb522d555a9b9851be48be56327d252d.tar.bz2
[3.10] gh-89047: Fix msecs computation so you never end up with 1000 msecs. (GH-96340) (GH-96342)
Diffstat (limited to 'Lib')
-rw-r--r--Lib/logging/__init__.py2
-rw-r--r--Lib/test/test_logging.py8
2 files changed, 9 insertions, 1 deletions
diff --git a/Lib/logging/__init__.py b/Lib/logging/__init__.py
index 19bd2bc..09810bd 100644
--- a/Lib/logging/__init__.py
+++ b/Lib/logging/__init__.py
@@ -325,7 +325,7 @@ class LogRecord(object):
self.lineno = lineno
self.funcName = func
self.created = ct
- self.msecs = (ct - int(ct)) * 1000
+ self.msecs = int((ct - int(ct)) * 1000) + 0.0 # see gh-89047
self.relativeCreated = (self.created - _startTime) * 1000
if logThreads:
self.thread = threading.get_ident()
diff --git a/Lib/test/test_logging.py b/Lib/test/test_logging.py
index af68f25..920bbeb6 100644
--- a/Lib/test/test_logging.py
+++ b/Lib/test/test_logging.py
@@ -4020,6 +4020,14 @@ class FormatterTest(unittest.TestCase, AssertErrorMessage):
f.converter = time.gmtime
self.assertEqual(f.formatTime(r), '21/04/1993 08:03:00')
+ def test_issue_89047(self):
+ f = logging.Formatter(fmt='{asctime}.{msecs:03.0f} {message}', style='{', datefmt="%Y-%m-%d %H:%M:%S")
+ for i in range(2500):
+ time.sleep(0.0004)
+ r = logging.makeLogRecord({'msg': 'Message %d' % (i + 1)})
+ s = f.format(r)
+ self.assertNotIn('.1000', s)
+
class TestBufferingFormatter(logging.BufferingFormatter):
def formatHeader(self, records):