+ record.msg = "{} ( callsite is {} of file \"{}\" at line {} )".format(record.msg, frame.f_code.co_name,inspect.getsourcefile(frame),inspect.getlineno(frame) )
+ return logging.Formatter.format(self, record)
+
+class BackTraceFormatter(logging.Formatter):
+ def __init__(self, *args, **kwargs):
+ logging.Formatter.__init__(self, *args, **kwargs)
+ def format(self, record):
+ import inspect
+ frame = inspect.currentframe()
+ # go upward of the stack to catch the effective callsite. Not very steady....
+ # should be replaced by an analysis of frame.f_code
+ for i in range(8):
+ frame = frame.f_back
+ record.msg = "{} ( callsite is {} of file \"{}\" at line {} )".format(record.msg, frame.f_code.co_name,inspect.getsourcefile(frame),inspect.getlineno(frame) )