From f2665073160f562035a1d25407e95438c9fafd27 Mon Sep 17 00:00:00 2001 From: Michael E Brown Date: Thu, 29 Nov 2007 01:56:28 -0600 Subject: log calling function name properly --- src/py-libs/trace_decorator.py | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/src/py-libs/trace_decorator.py b/src/py-libs/trace_decorator.py index 6c2743d..3594d0b 100755 --- a/src/py-libs/trace_decorator.py +++ b/src/py-libs/trace_decorator.py @@ -32,7 +32,8 @@ def traceLog(logger = moduleLog): message = message + "%s=%s" % (k,repr(v)) message = message + ")" - l2.handle(l2.makeRecord(l2.name, logging.DEBUG, filename, lineno, message, args=[], exc_info=None, func=func_name)) + frame = sys._getframe(2) + l2.handle(l2.makeRecord(l2.name, logging.DEBUG, os.path.normcase(frame.f_code.co_filename), frame.f_lineno, message, args=[], exc_info=None, func=frame.f_code.co_name)) try: result = "Bad exception raised: Exception was not a derived class of 'Exception'" try: @@ -61,10 +62,13 @@ if __name__ == "__main__": def testFunc(arg1, arg2="default", *args, **kargs): return 42 - try: - testFunc("hello", "world") - testFunc("happy", "joy", name="skippy") - testFunc("hi") - except: - import traceback - traceback.print_exc() + testFunc("hello", "world") + testFunc("happy", "joy", name="skippy") + testFunc("hi") + + @traceLog(log) + def testFunc22(): + return testFunc("archie", "bunker") + + testFunc22() + -- cgit