Caller's module name, function/method name and line number for output to logging

Malcolm Greene python at bdurham.com
Mon Jul 25 15:16:21 EDT 2016


Is there a technique for accessing a function's *CALLER* module name,
function/method name and line number so that this information can be
passed to a logging library's logger? I have a routine that detects an
error condition, but I want to report the error's context relative to
the caller, not the current function. TD;LR: I want to peek 1 level up
the call stack for this information. A bonus would be a way to have my
logger use info vs the current %(module)s, %(funcName)s, and
%(lineno)d values.
 
Thank you,
Malcolm



More information about the Python-list mailing list