[issue23597] Allow easy display of local variables in log messages?

Martin report at bugs.python.org
Fri Oct 29 02:27:23 EDT 2021


Martin <martin.schroeder at nerdluecht.de> added the comment:

In this pull request[1] I introduced a `format_locals` which can be provided to customize the serialization of the local variables of each frame. This could be used to filter out variables with certain names, for example. In this context, you could use a certain naming convention for variables with sensitive information and filter them out:

def _format_locals(filename, lineno, name, locals):
    return {k: repr(v) for k,v in locals.items() if not k.endsswith("_sensitive")}

traceback.TracebackException.from_exception(e, capture_locals=True, format_locals=format_locals).format()

(This should be exactly what Robert was suggesting.)


[1] https://github.com/python/cpython/pull/29299

----------
keywords: +patch
message_count: 3.0 -> 4.0
nosy: +moi90
nosy_count: 4.0 -> 5.0
pull_requests: +27572
stage:  -> patch review
pull_request: https://github.com/python/cpython/pull/29299

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


More information about the Python-bugs-list mailing list