crossbario / txaio

Utilities to support code that runs unmodified on Twisted and asyncio
MIT License
58 stars 30 forks source link

KeyError while logging #182

Closed pavelschon closed 2 years ago

pavelschon commented 2 years ago

I've got an unexpected error when trying to log a formatted dictionary:

$ python
Python 3.9.7 (default, Jun  1 2022, 14:59:30) 
[GCC 11.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import txaio
>>> print(txaio.__version__)
22.2.1
>>> txaio.use_asyncio()
>>> txaio.start_logging(level="info")
>>> log = txaio.make_logger()
>>> log.info(str({"hello": "world"}))
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File /site-packages/txaio/aio.py", line 161, in _log
    msg = format.format(**kwargs)
KeyError: "'hello'"
meejah commented 2 years ago

The structured logger here takes a "format string" as the first argument .. and those format strings use { and } characters. So e.g. try log.info("{foo}", foo={"hello": "world"}) or similar.

pavelschon commented 2 years ago

Thanks, so this is a user issue then.