Skip to content

[3.10] gh-89047: Fix msecs computation so you never end up with 1000 msecs. (GH-96340) (GH-96342) #96342

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 27, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Lib/logging/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,7 @@ def __init__(self, name, level, pathname, lineno,
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()
Expand Down
8 changes: 8 additions & 0 deletions Lib/test/test_logging.py
Original file line number Diff line number Diff line change
Expand Up @@ -4020,6 +4020,14 @@ class NoMsecFormatter(logging.Formatter):
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):
Expand Down