classification
Title: Improve logging performance when logger disabled
Type: enhancement Stage: resolved
Components: Library (Lib) Versions: Python 3.8
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: vinay.sajip Nosy List: vinay.sajip
Priority: normal Keywords: patch

Created on 2018-05-22 19:15 by vinay.sajip, last changed 2018-06-01 07:32 by vinay.sajip. This issue is now closed.

Pull Requests
URL Status Linked Edit
PR 7285 merged tuxtimo, 2018-05-31 13:17
Messages (3)
msg317328 - (view) Author: Vinay Sajip (vinay.sajip) * (Python committer) Date: 2018-05-22 19:15
If a logger is disabled (by setting it's disabled attribute to True), the check for this is done late in the dispatch of the logging event - during the handle() call - rather than isEnabledFor(), which would short-circuit some processing. So the check for logger.disabled should be moved to isEnabledFor().

Credit to Abhijit Gadgil for raising this:

https://stackoverflow.com/questions/50453121/logger-disabled-check-much-later-in-python-logging-module-whats-the-rationale
msg318368 - (view) Author: Vinay Sajip (vinay.sajip) * (Python committer) Date: 2018-06-01 07:16
The check in handle() should remain, because there are some scenarios where handle is called directly (e.g. when receiving events over a socket and dispatching to handlers). So the change would just be to add an additional check in isEnabledFor().
msg318369 - (view) Author: Vinay Sajip (vinay.sajip) * (Python committer) Date: 2018-06-01 07:29
New changeset 6e3ca645e71dd021fead5a70dc06d9b663612e3a by Vinay Sajip (Timo Furrer) in branch 'master':
bpo-33606: improve logging performance when logger is disabled (GH-7285)
https://github.com/python/cpython/commit/6e3ca645e71dd021fead5a70dc06d9b663612e3a
History
Date User Action Args
2018-06-01 07:32:21vinay.sajipsetstatus: open -> closed
resolution: fixed
stage: patch review -> resolved
2018-06-01 07:29:48vinay.sajipsetmessages: + msg318369
2018-06-01 07:16:46vinay.sajipsetmessages: + msg318368
2018-05-31 13:17:50tuxtimosetkeywords: + patch
stage: needs patch -> patch review
pull_requests: + pull_request6911
2018-05-22 19:15:59vinay.sajipcreate