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

Terry Reedy tjreedy at udel.edu
Mon Jul 25 17:07:19 EDT 2016


On 7/25/2016 3:16 PM, Malcolm Greene wrote:
> Is there a technique for accessing a function's *CALLER* module name,
> function/method name and line number so that this information can be

Look in the inspect module for the inspect stack function.  Note that 
when you call the function, it needs to look 2 levels up.

> 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.


-- 
Terry Jan Reedy




More information about the Python-list mailing list