How can I log current line, and stack info with Python?

前端 未结 8 1412
情深已故
情深已故 2021-02-02 11:01

I have logging function as follows.

logging.basicConfig(
    filename = fileName,
    format = \"%(levelname) -10s %(asctime)s %(message)s\",
    level = logging         


        
8条回答
  •  别跟我提以往
    2021-02-02 11:49

    import inspect
    import traceback
    
    def method():
       frame = inspect.currentframe()
       stack_trace = traceback.format_stack(frame)
       print ''.join(stack_trace)
    

    Use stack_trace[:-1] to avoid including method/printinfo in the stack trace.

提交回复
热议问题