You cannot easily change this. The goal of the logging module funcName
is to report exact locations of the source code line, not the function it represents. The idea is that you use it in combination with the lineno
and filename
entries to pinpoint the source code, not what function was called.
In order to achieve this, the log module uses code object introspection to determine the real function name:
def findCaller(self):
"""
Find the stack frame of the caller so that we can note the source
file name, line number and function name.
"""
f = currentframe()
#On some versions of IronPython, currentframe() returns None if
#IronPython isn't run with -X:Frames.
if f is not None:
f = f.f_back
rv = "(unknown file)", 0, "(unknown function)"
while hasattr(f, "f_code"):
co = f.f_code
filename = os.path.normcase(co.co_filename)
if filename == _srcfile:
f = f.f_back
continue
rv = (co.co_filename, f.f_lineno, co.co_name)
break
return rv
Short of reconstructing the _decorador
code object you cannot alter what is reported here. Reconstructing the code object can be done; you could build a facade function with exec
that calls the decorator, for example. But for this to work with a closure is more work than you should worry about, really.
I'd instead include the function name of the wrapped function:
logging.debug('This message should go to the log file (debug) (function %r)',
funcion)