跳转到主要内容

从文本中提取Python Tracebacks

项目描述

https://api.travis-ci.org/lmacken/tbgrep.png?branch=master https://coveralls.io/repos/lmacken/tbgrep/badge.png?branch=master https://pypip.in/v/tbgrep/badge.png https://pypip.in/d/tbgrep/badge.png

一个模块和命令行工具,用于从文本中提取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 (18.1 kB 查看散列值)

上传

由以下支持