Consider the example:
debug.py:
import logging
class log_funcname:
def __init__(self, the_logger):
self.the_logger = the_logger
def __call__(self, fn):
def simply_call(*args, **kwargs):
self.the_logger.critical(fn.func_name)
return fn(*args, **kwargs)
return simply_call
logger = logging.getLogger()
formatter = logging.Formatter("%(lineno)s")
ch = logging.StreamHandler()
ch.setFormatter(formatter)
logger.addHandler(ch)
@log_funcname(logger)
def hello():
pass
hello()
output:
$ python debug.py
10
I meant to create a function that calls the logger, passing it the line number and file name from where the execution really happened. If I wanted the example app to ouput 25 instead of 10, what should I change then?