All Projects → nir0s → Backtrace

nir0s / Backtrace

Licence: apache-2.0
Makes Python tracebacks human friendly

Programming Languages

python
139335 projects - #7 most used programming language

Projects that are alternatives of or similar to Backtrace

Tslog
📝 tslog - Expressive TypeScript Logger for Node.js.
Stars: ✭ 321 (+301.25%)
Mutual labels:  exceptions, stacktrace
Bugsnag React Native
Error monitoring and reporting tool for native exceptions and JS errors in React Native apps
Stars: ✭ 374 (+367.5%)
Mutual labels:  exceptions, stacktrace
Traceback with variables
Adds variables to python traceback. Simple, lightweight, controllable. Debug reasons of exceptions by logging or pretty printing colorful variable contexts for each frame in a stacktrace, showing every value. Dump locals environments after errors to console, files, and loggers. Works in Jupyter and IPython. Install with pip or conda.
Stars: ✭ 509 (+536.25%)
Mutual labels:  exceptions, stacktrace
Sentry Ruby
Sentry SDK for Ruby
Stars: ✭ 724 (+805%)
Mutual labels:  stacktrace
Sosl
StackOverflow Search Library
Stars: ✭ 10 (-87.5%)
Mutual labels:  exceptions
Rollbar Android
Rollbar for Android
Stars: ✭ 41 (-48.75%)
Mutual labels:  exceptions
Bugsnag Python
Official bugsnag error monitoring and error reporting for django, flask, tornado and other python apps.
Stars: ✭ 69 (-13.75%)
Mutual labels:  exceptions
Tracerr
Golang errors with stack trace and source fragments.
Stars: ✭ 646 (+707.5%)
Mutual labels:  stacktrace
Panic Overlay
Displays JS errors in browsers. Shows sources. Use with any framework. 💥✨
Stars: ✭ 50 (-37.5%)
Mutual labels:  stacktrace
Friendly Exception
An interface for an exception to be friendly
Stars: ✭ 41 (-48.75%)
Mutual labels:  exceptions
Bugsnag Android
Bugsnag crash monitoring and reporting tool for Android apps
Stars: ✭ 990 (+1137.5%)
Mutual labels:  exceptions
Backtrace
Ruby gem to print exception backtrace nicely
Stars: ✭ 14 (-82.5%)
Mutual labels:  exceptions
Bugsnag Android Ndk
DEPRECATED - this project now lives at bugsnag/bugsnag-android
Stars: ✭ 42 (-47.5%)
Mutual labels:  exceptions
Bugsnag Laravel
Bugsnag notifier for the Laravel PHP framework. Monitor and report Laravel errors.
Stars: ✭ 746 (+832.5%)
Mutual labels:  exceptions
Noexception
Java library for handling exceptions in concise, unified, and architecturally clean way.
Stars: ✭ 56 (-30%)
Mutual labels:  exceptions
Rxjava2debug
RxJava 2.x extension to provide meaningful Stack Traces
Stars: ✭ 673 (+741.25%)
Mutual labels:  stacktrace
Org Link Beautify
Beautify org links with colors and icons.
Stars: ✭ 50 (-37.5%)
Mutual labels:  beautify
Lme
An npm package to simply and beautifully log to console.
Stars: ✭ 29 (-63.75%)
Mutual labels:  beautify
Restfulsense
A RESTFul operations client that serializes responses and throws meaningful exceptions for >= 400 status codes.
Stars: ✭ 28 (-65%)
Mutual labels:  exceptions
Retrace
基于mapping.txt文件,根据原始class名或方法名获取混淆后的class名或方法名,根据混淆后的class名或方法名获取原始class名或方法名,堆栈还原等
Stars: ✭ 41 (-48.75%)
Mutual labels:  stacktrace

backtrace

WIP! Untested!

Travis Build Status AppVeyor Build Status PyPI Version Supported Python Versions Requirements Status Code Coverage Code Quality Is Wheel

backtrace manipulates Python tracebacks to make them more readable. It provides different configuration options for coloring and formatting.

backtrace also allows to choose the formatting of each part of the traceback; show the traceback entries in reversed order, and more..

Examples:

When piping to backtrace:

Trump? REALLY?! What a nation of idiots!

When using the API directly from Python:

Trump? REALLY?! What a nation of idiots!

NOTE: Didn't test this on Windows yet. Should work.. but don't know how well.

Alternatives

  • colored_traceback provides a way to color your tracebacks to make them more readable. It's a nice little tool but lacks actually re-formatting the traceback which is what the biggest problem is from my POV.
  • Um.. your own implementation? There's really a reason for me doing this. I do have a life you know (well.. I try anyway).

Installation

backtrace officially supports Linux and OSX on Python 2.7 and 3.4+. Python 2.6 will also probably work, but with no guarantees.

pip install backtrace

For dev:

pip install https://github.com/nir0s/backtrace/archive/master.tar.gz

Usage

backtrace provides two methods for manipulating your tracebacks.

  • Piping to backtrace using its CLI
  • Using backtrace from within your code

Piping

You can pipe stderr into backtrace which will try to detect a traceback, parse it and display a beautified trace.

$ backtrace -h
usage: backtrace [-h] [-r] [-a] [-s] [-c]

Beautify Tracebacks.

Just pipe stderr into backtrace like so:
  `python bad-program.py 2>&1 | backtrace`

optional arguments:
  -h, --help          show this help message and exit
  -r, --reverse       Reverse traceback entry order
  -a, --align         Right-align the backtrace
  -s, --strip-path    Strip the path to the module
  -c, --conservative  Activate conservative mode

$ python my-traceback-generating-program.py 2>&1 | backtrace
...

Inside your application

import backtrace

backtrace.hook(
    reverse=False,
    align=False,
    strip_path=False,
    enable_on_envvar_only=False,
    on_tty=False,
    conservative=False,
    styles={})

# more code...

# if you wanna restore the default hook...
backtrace.unhook()
...

You can pass the following flags to hook to change backtrace's behavior:

  • If reverse is True, the traceback entries will be printed in reverse order.
  • If align is True, all parts (line numbers, file names, etc..) will be aligned to the left according to the longest entry. This allows for extended readability as your eyes don't have to move between columns to understand what's going on.
  • If strip_path is True, only the file name will be shown, not its full path. This is useful when you know you're running in the context of a single module or a single package containing only a root folder so you only need file names. This can help keep the traceback clean.
  • If enable_on_envvar_only is True, only if the environment variable ENABLE_BACKTRACE is set, backtrace will be activated.
  • If on_tty is True, backtrace will be activated only if you're running in a real terminal (i.e. not piped, redirected, etc..). This can help keep the original traceback when logging to files or piping to look for information.
  • styles is a dictionary containing the styling for each part of the rebuilt traceback. See below.
  • If conservative is true, a more conservative format will be provided for people who find the default backtrace style too new or intimidating. For example, no alignment will be done (unless align is explicitly passed), styles will be ignored, and potential unnecessary data will be retained. Try It! It's still eye-candy.

Styles

Styles allow you to customize the coloring and structure of your new traceback. The defaults are:

STYLES = {
    'backtrace': Fore.YELLOW + '{0}',
    'error': Fore.RED + Style.BRIGHT + '{0}',
    'line': Fore.RED + Style.BRIGHT + '{0}',
    'module': '{0}',
    'context': Style.BRIGHT + Fore.GREEN + '{0}',
    'call': Fore.YELLOW + '--> ' + Style.BRIGHT + '{0}',
}

Where:

  • backtrace is the main traceback message.
  • error is the error message presenting the exception message and its type.
  • line is the line number of each entry.
  • module is the calling module of each entry.
  • context is the calling function/method of each entry.
  • call is the called function/method/assignment of each entry.

and the {0} format place holder is the actual value of the field.

Sending a partial dictionary containing changes in only some parts of the traceback will have backtrace use the defaults for whatever wasn't specified.

You can do all sorts of stuff like removing a certain field by setting the formatting of that field to an empty string; add more verbose identifiers to each field by appending an ID in front of it or just adding paranthese around a field.

Coloring

Coloring is powered by colorama.

Testing

To see an example printout:

$ python test.py
git clone [email protected]:nir0s/backtrace.git
cd backtrace
pip install tox
tox

Contributions..

See CONTRIBUTIONS

Pull requests are always welcome..

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].