importlogginglogging.basicConfig(filename='example.log', format='{msecs:03d} - {message}', style='{')
logging.warning('foo')--- Logging error ---Traceback (most recent call last): File "...\Python\Python310\lib\logging\__init__.py", line 1100, in emit msg = self.format(record) File "...\Python\Python310\lib\logging\__init__.py", line 943, in format return fmt.format(record) File "...\Python\Python310\lib\logging\__init__.py", line 681, in format s = self.formatMessage(record) File "...\Python\Python310\lib\logging\__init__.py", line 650, in formatMessage return self._style.format(record) File "...\Python\Python310\lib\logging\__init__.py", line 440, in format return self._format(record) File "...\Python\Python310\lib\logging\__init__.py", line 458, in _format return self._fmt.format(**values)ValueError: Unknown format code 'd' for object of type 'float'Call stack: File "...\main.py", line 26, in <module> logging.warning('foo')Message: 'foo'Arguments: ()importlogginglogging.basicConfig(filename='example.log', format='{msecs:03.0f} - {message}', style='{')
logging.warning('foo')
Documentation
%-formatting (It works)
example.log:
✅
Now using the the modern {} format syntax, as the documentation says (doesn't work)
❌
Exception:
Proposed fix
Use
{msecs:03.0f}placeholder.example.log:
✅
Linked PRs