I would like to log a number formatted with commas, but using the delayed interpolation method.
some_num = 1234567
# This does the formatting like I want:
logger.info(f'Number = {some_num:,}'
>> Number = 1,234,567
# But I want to use this syntax:
logger.info(f'Number = %d', some_num)
>> Number = 1234567
Is there a way to use the ("%d", variable)
and add optional formatting options?
The reason I'd prefer to use that method (instead of str.format
or f-strings) is because it'd be consistent with the logging in the rest of the application, and which, if the logging level is set higher than a given log message, then the message will not interpolate the variables.
Edit
To be pedantic, I don't want to use f-strings, nor the old '%s' % my_var
form, or str.format
. I want to use logging
's placeholders (%s, %d, %i
, etc.) but be able to add commas to numbers.
Example:
# What I'm trying to do
logger.info('Number = %d:,', some_num)
>> 1,234,567