[New-bugs-announce] [issue33165] Add stacklevel parameter to logging APIs

Nick Coghlan report at bugs.python.org
Wed Mar 28 05:05:21 EDT 2018


New submission from Nick Coghlan <ncoghlan at gmail.com>:

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)

----------
components: Library (Lib)
messages: 314578
nosy: ncoghlan, vinay.sajip
priority: normal
severity: normal
stage: needs patch
status: open
title: Add stacklevel parameter to logging APIs
type: enhancement
versions: Python 3.8

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue33165>
_______________________________________


More information about the New-bugs-announce mailing list