Change from f'strings' to %strings
JonasKs opened this issue · comments
Thanks to @BBT#8008
at the Django Discord for reporting this.
Three issues of f'strings'
in logging:
- If interpolation fails, code will break because it's not handled by the logging module
- Tools like Sentry aggregate logs based on the log template string, interpolating before that will make them show up as different errors/messages, while they are actually the same
- Interpolation is done even if the message is not to be logged
So, changing from
logger.info(f'{given_guid} is not a valid GUID. New GUID is {new_guid}')
to
logger.info("%s is not a valid GUID. New GUID is %s", given_guid, new_guid)
Will ensure the opposites of the points above:
- If the interpolation fails, code will not break because it's handled by the logging module
- Tools like Sentry will behave correctly
- Interpolation is only done if the message is to be logged