Giter VIP home page Giter VIP logo

tbgrep's Introduction

Traceback Grep

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

A module & command-line tool for extracting Python tracebacks from text.

Extracting tracebacks from bunch of files

$ tbgrep file1 file2 file3

Grepping for tracebacks in a pipeline

$ tail -f logfile | tbgrep

Displaying all unique tracebacks ordered by the number of occurrences

$ 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

Using the Python API

Once instantiated, you pass each line to the process method, which will return either None, or a string of a traceback.

from tbgrep import TracebackGrep

extractor = TracebackGrep()
for line in file('logfile'):
    tb = extractor.process(line)
    if tb:
        print(tb)

Instead of displaying each traceback found in the file, tbgrep also supports generating statistics about all tracebacks in the file.

extractor = TracebackGrep(stats=True)
for line in file('logfile'):
    extractor.process(line)
extractor.print_stats()

There are also some functions that allow you to search for tracebacks in a more convenient way.

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')))

Supported Input Formats

tbgrep can extract tracebacks from logs of various formats. For example, CherryPy starts the traceback on a line with other details (like module, timestamp, etc), but the rest of the trace starts at the beginning of the line. Apache logs, on the other hand, will prefix each line of the traceback with this information. tbgrep is designed to handle these kinds of situations

tbgrep's People

Contributors

lmacken avatar msabramo avatar onyman avatar ralphbean avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.