Skip to main content

Extract Python Tracebacks from text

Project description

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

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 these kinds of situations

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

tbgrep-0.2.0.tar.gz (3.6 kB view details)

Uploaded Source

File details

Details for the file tbgrep-0.2.0.tar.gz.

File metadata

  • Download URL: tbgrep-0.2.0.tar.gz
  • Upload date:
  • Size: 3.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for tbgrep-0.2.0.tar.gz
Algorithm Hash digest
SHA256 5763d831c875b569c5ade3a14535dc6592bf6bc96b9c9b8c6e6605571844895d
MD5 ec7c5a8da8919972100431378ae24bf9
BLAKE2b-256 5e9b5a0f67b67b14a58d575b7a9bca34ddbfe5a97868131583fb73a244f8714f

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page