10 ms·
The example of f-string in the article is quite unfortunate, it suggests using it for logging messages. F-strings shouldn't be used in loggers, because they are
by gbajson 7y ago
The example of f-string in the article is quite unfortunate, it suggests using it for logging messages.
F-strings shouldn't be used in loggers, because they aren't lazy evaluated.
- bonoboTP 7y agoWhat instead?
- gbajson 7y agoStandard logging functions, without f-strings. So instead of: logging.debug(f'Problem with {x}') use: logging.debug('Problem with %s', x).
- masklinn 7y agoTBF for the vast majority of logging it doesn't really matter. Not to mention the laziness is only the (usually cheap) formatting itself. If you're logging the result of non-trivial expressions (which would otherwise not be computed at all) you have to handroll it. f-strings are mostly unusable for translatable contexts. And format-strings also don't work then (they're a security issue).
- gbajson 7y agoI already experienced performance issue, just because log messages (millions/s) were evaluated, for logger in debug mode, so it really depends on the system.
- tasubotadas 7y agoA cookie for this man!