0
我想提取追踪错误的细节,那些回溯从日志文件中提取使用this method,并有许多不同种类的回溯中,象下面这样:如何使用python正则表达式从traceback中提取错误细节?
Traceback (most recent call last):
File "/usr/lib/python2.7/runpy.py", line 174, in _run_module_as_main
"__main__", fname, loader, pkg_name)
File "/usr/lib/python2.7/runpy.py", line 72, in _run_code
exec code in run_globals
File "/root/env/common/test/test/__main__.py", line 5, in <module>
main()
File "/root/env/common/test/test/cli/parser.py", line 55, in main
run_script(args)
File "/root/env/common/test/test/cli/runner.py", line 124, in run_script
exec_script(args.script, scope=globals(), root=True)
File "/root/workspace/group/test_regression_utils.py", line 123, in exec_script
cli_exec_script(*args,**kwargs)
File "/root/env/common/test/test/cli/runner.py", line 186, in exec_script
exec(compile(code, scriptpath, 'exec')) in scope
File "shiju_12.py", line 30, in <module>
File "/root/moaworkspace/group/testscript/utils/shiju_public.py", line 37, in shiju_move
Exception: close failed!
EndOfStream
EndOfStream
Traceback (most recent call last):
File "/usr/lib/python2.7/runpy.py", line 174, in _run_module_as_main
"__main__", fname, loader, pkg_name)
File "/usr/lib/python2.7/runpy.py", line 72, in _run_code
exec code in run_globals
File "/root/env/common/test/test/__main__.py", line 5, in <module>
main()
File "/root/env/common/test/test/cli/parser.py", line 55, in main
run_script(args)
File "/root/env/common/test/test/cli/runner.py", line 124, in run_script
exec_script(args.script, scope=globals(), root=True)
File "/root/env/common/test/test/cli/runner.py", line 186, in exec_script
exec(compile(code, scriptpath, 'exec')) in scope
File "/root/env/common/mator/mator/mator.py", line 520, in start
raise IOError("RPC server not started!")
IOError: RPC server not started
的预期结果是:
("XXXX", "Exception: close failed!")
("XXXX","IOError: RPC server not started")
我试图detail_regex = r'Traceback.*\n(\s+.*\n)*(.*)\n*'
第二回溯是正确的,但第一个回溯的结果是("Exception: close failed!", "EndOfStream")
任何IDE如?
这可能是一个更好的主意,检查追溯对象(不记得确切地说,他们被称为虽然)。 – SwiftsNamesake
哦,回溯是从日志文件中获得的。 – nanci
该链接指向回答这个问题 – SwiftsNamesake