从文本中提取Python Tracebacks
项目描述
一个模块和命令行工具,用于从文本中提取Python Tracebacks。
从大量文件中提取tracebacks
$ tbgrep file1 file2 file3
在管道中搜索tracebacks
$ tail -f logfile | tbgrep
按出现次数排序显示所有唯一的tracebacks
$ tbgrep --stats logfile
[...]
== 99 occurences ==================================================
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方法,该方法将返回None或一个traceback字符串。
from tbgrep import TracebackGrep
extractor = TracebackGrep()
for line in file('logfile'):
tb = extractor.process(line)
if tb:
print(tb)
tbgrep还支持生成关于文件中所有tracebacks的统计信息,而不是显示文件中找到的每个traceback。
extractor = TracebackGrep(stats=True)
for line in file('logfile'):
extractor.process(line)
extractor.print_stats()
还有一些函数允许您以更方便的方式搜索tracebacks。
from tbgrep import (
tracebacks_from_lines, tracebacks_from_file,
last_traceback_from_file)
for tb in tracebacks_from_file(file('logfile')):
print(tb)
for tb in tracebacks_from_file(file('logfile'), reverse=True):
print(tb)
print(last_traceback_from_file(file('logfile')))
支持的输入格式
tbgrep可以从各种格式的日志中提取堆栈跟踪。例如,CherryPy从带有其他详细信息(如模块、时间戳等)的行开始堆栈跟踪,但其余的堆栈跟踪从行的开头开始。另一方面,Apache日志将为堆栈跟踪的每一行添加此信息。tbgrep旨在处理这类情况
项目详情
关闭
tbgrep-0.3.0.tar.gz 的散列值
算法 | 散列摘要 | |
---|---|---|
SHA256 | 53f0ec46ee24ce24cf2a178ac33de69e579e36d8a474c55fd564614146b5810d |
|
MD5 | c57fb085a0710c2848a676832a76847e |
|
BLAKE2b-256 | 4f0dd411b33432dbeb419d743e28c33094516d2261ba0dca20dd9ad170ba62b3 |