Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

You should not use f-strings for logging, because that performs all the formatting _before_ the logging module determines if the log needs to be printed. You want the formatting overhead to happen only for logs that will get printed. You can’t achieve that with f-strings, just use normal logging calls.

It kinda speaks bad of the auto-completion that it suggests such anti-pattern.



You can do this with the new t strings! They’re like f strings, but a template instead. https://peps.python.org/pep-0750/




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: