classification
Title: Add stacklevel parameter to logging APIs
Type: enhancement Stage: resolved
Components: Library (Lib) Versions: Python 3.8
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: ncoghlan, vinay.sajip
Priority: normal Keywords: patch

Created on 2018-03-28 09:05 by ncoghlan, last changed 2018-06-05 16:26 by vinay.sajip. This issue is now closed.

Pull Requests
URL Status Linked Edit
PR 7424 merged vinay.sajip, 2018-06-05 11:52
Messages (2)
msg314578 - (view) Author: Nick Coghlan (ncoghlan) * (Python committer) Date: 2018-03-28 09:05
warnings.warn() offers a stacklevel parameter to make it easier to write helper functions that generate warnings - by passing "stacklevel=2", you can ensure the warning is attributed to the caller of the helper function, rather than to the helper function itself.

There isn't currently a similarly clear way to write helper functions that emit logging messages - if the format includes "pathname", "filename", "module", "function", or "lineno", then those will always report the location of the helper function, rather than the caller of the helper function.

It would be convenient if logging.debug() et al accepted a "stacklevel" parameter the same way the warnings module does (although this may require some adjustments to the Logger.findCaller method API)
msg318764 - (view) Author: Vinay Sajip (vinay.sajip) * (Python committer) Date: 2018-06-05 16:24
New changeset dde9fdbe453925279ac3d2a6a72102f6f9ef247c by Vinay Sajip in branch 'master':
bpo-33165: Added stacklevel parameter to logging APIs. (GH-7424)
https://github.com/python/cpython/commit/dde9fdbe453925279ac3d2a6a72102f6f9ef247c
History
Date User Action Args
2018-06-05 16:26:27vinay.sajipsetstatus: open -> closed
resolution: fixed
stage: patch review -> resolved
2018-06-05 16:24:20vinay.sajipsetmessages: + msg318764
2018-06-05 11:52:39vinay.sajipsetkeywords: + patch
stage: needs patch -> patch review
pull_requests: + pull_request7049
2018-03-28 09:05:21ncoghlancreate