First three paragraphs of this section state one might use {}-formatting for logging format string.
If you are using {}-formatting (str.format()), you can use {attrname} as the placeholder in the format string.
However, it does not work.
import logging
logging.basicConfig(level=logging.INFO, format='[{asctime}] {message}')
logging.info('foo')
Prints,
[{asctime}] {message}
What is wrong?
You need to declare your formatting style:
import logging
logging.basicConfig(level=logging.INFO, format='[{asctime}] {message}', style='{')
logging.info('test')
Works fine:
[2020-03-24 14:44:02,214] test
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With