Author nhua
Recipients nhua
Date 2020-03-24.07:21:17
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1585034477.86.0.546029969231.issue40053@roundup.psfhosted.org>
In-reply-to
Content
As I see, Python's logging module's implementation has a nice property that, when no additional args are passed in, the msg (first argument) will be directly printed.

For example, logging.error('abc %s') can be handled peacefully with printing "ERROR:root:abc %s" in the log.

However, the logging's documentation only said the followings:
"The msg is the message format string, and the args are the arguments which are merged into msg using the string formatting operator."

From what I see, this implementation (seems the case for both Python2 and Python3) has many benefits: saving CPU resources, safe handling pre-formated string, etc. More importantly, it also de-facto allows using the convenient f-string in logging statement, e.g. 

logging.error(f'Started at {start_time}, finished at {finish_time}'
              f' by user {user}')

can run correctly and smoothly even with user containing %s inside.

In summary, I hope this de-facto actual behavior can be officially endorsed, with wordings like,
"When *args is empty, i.e. no additional positional arguments passed in, the msg be of any string (no need to be a format string) and will be directly used as is without interpolation."

What do you think? Thank you a lot!
History
Date User Action Args
2020-03-24 07:21:17nhuasetrecipients: + nhua
2020-03-24 07:21:17nhuasetmessageid: <1585034477.86.0.546029969231.issue40053@roundup.psfhosted.org>
2020-03-24 07:21:17nhualinkissue40053 messages
2020-03-24 07:21:17nhuacreate