classification
Title: Document the behavior that no interplotation is applied when no *args are passed in for logging statements
Type: behavior Stage: resolved
Components: Documentation Versions: Python 3.9, Python 3.8, Python 3.7
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: docs@python Nosy List: docs@python, eric.smith, nhua, vinay.sajip
Priority: normal Keywords:

Created on 2020-03-24 07:21 by nhua, last changed 2020-03-26 17:37 by eric.smith. This issue is now closed.

Messages (4)
msg364920 - (view) Author: Nan Hua (nhua) Date: 2020-03-24 07:21
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!
msg364922 - (view) Author: Eric V. Smith (eric.smith) * (Python committer) Date: 2020-03-24 09:12
I think it's important that logging has this feature for the reasons stated, so it should be documented.

And hopefully it's also tested for, but I haven't looked.
msg365099 - (view) Author: Nan Hua (nhua) Date: 2020-03-26 17:23
Note that this issue has already been mostly addressed by 
https://github.com/python/cpython/pull/19132. I think we can close this issue now. Thanks Eric, Gregory and Vinay!
msg365100 - (view) Author: Eric V. Smith (eric.smith) * (Python committer) Date: 2020-03-26 17:37
Thanks for the bug report! I'll mark it "fixed". If there's more to do, let us know.
History
Date User Action Args
2020-03-26 17:37:23eric.smithsetresolution: fixed
messages: + msg365100
2020-03-26 17:23:14nhuasetstatus: open -> closed

messages: + msg365099
stage: needs patch -> resolved
2020-03-24 09:12:02eric.smithsetassignee: docs@python
components: + Documentation, - Library (Lib)
versions: + Python 3.7, Python 3.8
nosy: + eric.smith, docs@python

messages: + msg364922
stage: needs patch
2020-03-24 07:56:29xtreaksetnosy: + vinay.sajip
2020-03-24 07:21:17nhuacreate