20/20视野的日志
retrospect的Python项目详细描述
事后动态日志记录
经典的伐木期望完美的远见,但只有事后才是20/20!
用法
通过pip安装,然后输入shell:
defhello(a,b=2):"""docstring"""a=1c=b*2a=b=c=a*2+b*cprint('output: a={} b={} c={}'.format(a,b,c))returna,b,cimportretrospectretro=retrospect.FunctionRetrospector(hello)
现在您可以开始实时检查行:
>>>retro.implement(lines=True)>>>hello(10)((3,SetLineno,3),{'a':10,'b':2})((4,SetLineno,4),{'a':1,'b':2})((5,SetLineno,5),{'a':1,'b':2,'c':4})((6,SetLineno,6),{'a':10,'b':10,'c':10})output:a=10b=10c=10((7,SetLineno,7),{'a':10,'b':10,'c':10})((7,RETURN_VALUE,None),{'a':10,'b':10,'c':10})
或一组特定的行:
>>>retro.implement(lines=[4],boundaries=False)>>>hello(20)((4,SetLineno,4),{'a':1,'b':2})output:a=10b=10c=10
或仅在符号更改时:
>>>retro.implement(symbols=True,boundaries='start')>>>hello(30)((3,SetLineno,3),{'a':30,'b':2})((3,STORE_FAST,'a'),{'a':30,'b':2})((3,STORE_FAST,'a'),{'a':1,'b':2})((4,STORE_FAST,'c'),{'a':1,'b':2})((4,STORE_FAST,'c'),{'a':1,'b':2,'c':4})((5,STORE_FAST,'a'),{'a':1,'b':2,'c':4})((5,STORE_FAST,'a'),{'a':10,'b':2,'c':4})((5,STORE_FAST,'b'),{'a':10,'b':2,'c':4})((5,STORE_FAST,'b'),{'a':10,'b':10,'c':4})((5,STORE_FAST,'c'),{'a':10,'b':10,'c':4})((5,STORE_FAST,'c'),{'a':10,'b':10,'c':10})output:a=10b=10c=10
或特定的操作码:
>>>retro.implement(opcodes=['LOAD_CONST'],boundaries='finish')>>>hello(40)((3,LOAD_CONST,1),{'a':40,'b':2})((4,LOAD_CONST,2),{'a':1,'b':2})((5,LOAD_CONST,2),{'a':1,'b':2,'c':4})((6,LOAD_CONST,'output: a={} b={} c={}'),{'a':10,'b':10,'c':10})output:a=10b=10c=10((7,RETURN_VALUE,None),{'a':10,'b':10,'c':10})
或者返回到exact原始:
>>>retro.implement()>>>hello(50)output:a=10b=10c=10
以上任何一种都可以根据需要进行混合,例如lines=True, symbols="c"