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

前端 未结 8 1174
情深已故
情深已故 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:33

    Look at traceback module

    >>> import traceback
    >>> def test():
    >>>     print "/".join( str(x[2]) for x in traceback.extract_stack() )
    >>> def main():
    >>>     test()
    >>> main()
    /launch_new_instance/mainloop/mainloop/interact/push/runsource/runcode//main/test
    

提交回复
热议问题