Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does python logging module use old string formatting?

Python has two main string formatting options % and str.format. logging module has a lazy feature.

logging.debug('The value is %s', huge_arg)

This does not construct the string if the log line is not going to be print. However, this feature works only if the sting uses old style % format. Is there a way to use str.format with this lazy feature? There could be a named arg like:

logging.debug('The value is {}', fmt_arg=(huge_arg))
like image 748
balki Avatar asked Sep 15 '26 06:09

balki


1 Answers

The only answer to your question is that - so far - nobody has volunteered to change the logging code to support the newer format feature. If you're volunteering, why not ask about it on the Python-Dev mailing list? I expect it's trickier than you realize (e.g., there may be calls to logging functions already that happen to pass a fmt_arg keyword argument). Good luck ;-)

like image 79
Tim Peters Avatar answered Sep 17 '26 21:09

Tim Peters



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!