从文本中提取python回溯
tbgrep的Python项目详细描述
用于从文本中提取python回溯的模块和命令行工具。
从一堆文件中提取回溯
$ tbgrep file1 file2 file3
管道中回溯的重映射
$ tail -f logfile | tbgrep
显示按出现次数排序的所有唯一回溯
$ tbgrep --stats logfile [...]==99occurences================================================== Traceback (most recent call last): File "/usr/lib/python2.4/site-packages/bodhi/admin.py", line 209, in _masher_request req_params=kwargs) File "/usr/lib/python2.4/site-packages/fedora/client/proxyclient.py", line 285, in send_request raise AuthError(_('Unable to log into server. Invalid' AuthError: Unable to log into server. Invalid authentication tokens. Send new username and password==================================================================733 unique tracebacks extracted
使用python api
一旦实例化,就将每一行传递给process方法,它将 要么不返回,要么返回一个回溯字符串。
fromtbgrepimportTracebackGrepextractor=TracebackGrep()forlineinfile('logfile'):tb=extractor.process(line)iftb:print(tb)
tbgrep也不显示文件中找到的每个回溯 支持生成文件中所有回溯的统计信息。
extractor=TracebackGrep(stats=True)forlineinfile('logfile'):extractor.process(line)extractor.print_stats()
还有一些函数允许您在 方便的方式。
fromtbgrepimport(tracebacks_from_lines,tracebacks_from_file,last_traceback_from_file)fortbintracebacks_from_file(file('logfile')):print(tb)fortbintracebacks_from_file(file('logfile'),reverse=True):print(tb)print(last_traceback_from_file(file('logfile')))
支持的输入格式
tbgrep可以从各种格式的日志中提取回溯。例如, cherrypy在一行中开始回溯其他细节(比如模块, 时间戳等),但跟踪的其余部分从行的开头开始。 另一方面,apache日志将在回溯的每一行前面加上前缀 这个信息。tbgrep旨在处理此类情况