You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
logging Formatter behavior when using msecs and braces : '{' #89047
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
assignee=Noneclosed_at=Nonecreated_at=<Date2021-08-11.05:43:18.060>labels= ['type-bug', 'library', '3.11']
title="logging Formatter behavior when using msecs and braces : '{'"updated_at=<Date2021-11-30.13:00:54.821>user='https://bugs.python.org/fxcallewaert'
All very reasonable. I know my date time formatting and my brace formatting so I'm good or am I ...
>>> import time, math
>>> for i in range(2500): a= (lambda : (time.sleep(0.0004), (logging.error("Whaaat!") )if math.modf(time.time())[0]>0.9995 else 0))()
...
2021-08-11 01:26:40.1000 Whaaat!
You'll hopefully agree that formatting a msecs as 1000 is plain wrong.
Can I get around this ? the best / simplest, I've found is
>>> logging.Formatter.default_msec_format = "%s.%03d"
>>> logging.getLogger().handlers[0].setFormatter(logging.Formatter(fmt='{asctime} {message}', style='{'))
>>> for i in range(2500): a= (lambda : (time.sleep(0.0004), (logging.error("Now that's ok") )if math.modf(time.time())[0]>0.9995 else 0))()
...
2021-08-11 01:33:46.999 Now that's ok
Having to rely / teach /learn about "Old string formatting" in 2021 is not ideal.
Can you suggest something better ?
or would it be palatable to make a "careful" modification in logging/init.py (see below) ?
replace
self.msecs = (ct - int(ct)) * 1000
by
self.msecs = math.floor((ct - int(ct)) * 1000) #requires importing math
Activity
fxcallewaert commentedon Aug 11, 2021
Wait. I come from a place where we use '.' as a decimal separator ...
All very reasonable. I know my date time formatting and my brace formatting so I'm good or am I ...
You'll hopefully agree that formatting a msecs as 1000 is plain wrong.
Can I get around this ? the best / simplest, I've found is
Having to rely / teach /learn about "Old string formatting" in 2021 is not ideal.
Can you suggest something better ?
or would it be palatable to make a "careful" modification in logging/init.py (see below) ?
replace
by
or
pythongh-89047: Fix msecs computation so you never end up with 1000 m…
gh-89047: Fix msecs computation so you never end up with 1000 msecs. (G…
pythongh-89047: Fix msecs computation so you never end up with 1000 m…
pythongh-89047: Fix msecs computation so you never end up with 1000 m…
[3.11] gh-89047: Fix msecs computation so you never end up with 1000 …
[3.10] gh-89047: Fix msecs computation so you never end up with 1000 …