We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
LogRecord.msecs returns an incorrect value when timestamp (self.ct) value has exactly 100ms.
LogRecord.msecs
self.ct
One liner check:
assert int((1677793338.100_000_0 - int(1677793338.100_000_0)) * 1000) + 0.0 == 100.0
The issue is binary representation of "0.1" / floating point error:
>>> # Definition of LogRecord.msecs: >>> # https://github.com/python/cpython/blob/12011dd8bafa6867f2b4a8a9e8e54cb0fbf006e4/Lib/logging/__init__.py#L343 >>> # int((ct - int(ct)) * 1000) + 0.0 >>> ct = 1677793338.100_000_0 >>> ct 1677793338.1 >>> ct - int(ct) 0.09999990463256836 >>> _ * 1000 99.99990463256836 >>> int(_) 99 >>> _ + 0.0 99.0
I think switching to time.time_ns when setting the creation time might be one solution.
time.time_ns
time.time_ns()
logging.LogRecord
Bug report
LogRecord.msecsreturns an incorrect value when timestamp (self.ct) value has exactly 100ms.One liner check:
The issue is binary representation of "0.1" / floating point error:
Your environment
Discussion
I think switching to
time.time_nswhen setting the creation time might be one solution.Linked PRs
time.time_ns()inlogging.LogRecord#102412