I'm trying to use str.format
style templating in my logging. Can't seem to get it working properly.
>>> import logging
>>> logging.basicConfig(filename='/tmp/example', format='{asctime} - {levelname} - {message}', style='{', level=logging.INFO)
>>> logger = logging.getLogger(__name__)
>>> logger.warning('blah')
>>> logger.warning('{foo:03d}', {'foo': 42})
Actual output:
2017-02-23 16:11:45,695 - WARNING - blah
2017-02-23 16:12:11,432 - WARNING - {foo:03d}
Expected output:
2017-02-23 16:11:45,695 - WARNING - blah
2017-02-23 16:12:11,432 - WARNING - 042
What am I missing in this setup?
I'm not interested to see workarounds that format the string before it's logged, or Python 2 solutions which use old %-style templating.