New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
No f-string in logging.basicConfig() #85948
Comments
There is no method to implement format strings in the basicConfig() method of the logging module. There are the implementations of '%', '{' or '$' for printf-style, str.format() or string.Template respectively using the style keyword. |
Since an f-string just evaluates to a regular string at the call site, before any logging code is invoked, there's nothing for the logging code to do. As far as it's concerned, it just gets a regular string. |
It's as Eric said. So I'll close this issue as "not a bug". An additional point - by using f-strings, you may be doing unnecessary string formatting - e.g. if the event doesn't actually get handled because of logger or handler level or filter settings. It's worse if any of the parameters in the f-string are expensive to compute, as they would effectively be thrown away if the event were not to be handled. |
Vinay raises a good point about performance that's well worth being aware of, especially with expensive objects (as he says). But since f-strings are much faster than other formatting (and especially .format()), there's a tradeoff. If I have something that I know is likely to be logged, sometimes I'll format it with f-strings. |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: