Skip to content

Commit 0251655

Browse files
authored
Update README.md
1 parent d56a4c8 commit 0251655

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

README.md

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -58,23 +58,23 @@ TypeError: unsupported operand type(s) for +: 'int' and 'str'
5858
```
5959
I rarely use this locally instead of a real debugger, but it helps me sleep when my code runs somewhere where the only debug tool is a log file (though it's not a fully-grown [error monitoring system](https://sentry.io/welcome/)).
6060

61-
By default, it tries to be somewhat polite about screen space (showing only a handful of source lines & the function header, and only the variables _in those lines_, and only (?) 500 characters per variable). You can [configure](https://github.com/cknd/stackprinter/blob/master/stackprinter/__init__.py#L28-L137) exactly how verbose things should be.
61+
By default, it tries to be somewhat polite about screen space, showing only a few source lines & the function header, and only the variables _that appear in those lines_, and using only (?) 500 characters per variable. You can [configure](https://github.com/cknd/stackprinter/blob/master/stackprinter/__init__.py#L28-L149) exactly how verbose things should be.
6262

6363
It outputs plain text normally, which is good for log files. There's also a color mode for some reason 🌈, with a few different color schemes for light and dark backgrounds. (The colors [track different variables](https://medium.com/@brianwill/making-semantic-highlighting-useful-9aeac92411df) instead of the language syntax.)
6464

6565
<img src="https://raw.githubusercontent.com/cknd/stackprinter/master/notebook.png" width="500">
6666

6767
# Usage
6868

69-
## Exception logging
70-
To replace the default python crash printout, call `set_excepthook()` somewhere. This will print detailed stacktraces for any uncaught exception except KeyboardInterrupts (to stderr, by default). You could also [make this permanent for your python installation](#making-it-stick).
69+
## Option 1: Set and forget
70+
To replace the default python crash printout, call `set_excepthook()` somewhere once. Afterwards, any uncaught exception will be printed with an extended traceback (to stderr, by default). You could also [make this permanent for your python installation](#making-it-stick).
7171

7272
```python
7373
import stackprinter
7474
stackprinter.set_excepthook(style='darkbg2') # for jupyter notebooks try style='lightbg'
7575
```
76-
77-
For more control, call [`show()`](https://github.com/cknd/stackprinter/blob/master/stackprinter/__init__.py#L154-L162) or [`format()`](https://github.com/cknd/stackprinter/blob/master/stackprinter/__init__.py#L28-L137) inside an `except` block. `show()` prints to stderr by default, `format()` returns a string, for custom logging.
76+
## Option 2: Call it selectively during exception handling
77+
For more control, call [`show()`](https://github.com/cknd/stackprinter/blob/master/stackprinter/__init__.py#L166-L183) or [`format()`](https://github.com/cknd/stackprinter/blob/master/stackprinter/__init__.py#L28-L149) inside an `except` block. `show()` prints to stderr, `format()` returns a string, for custom logging.
7878

7979
```python
8080
try:
@@ -97,7 +97,7 @@ except RuntimeError as exc:
9797

9898
### Config options
9999

100-
`format()`, `show()` and `set_excepthook()` accept a common set of keyword args. They allow you to tweak the formatting, hide certain variables by name, skip variables in calls within certain files, and some other stuff. For all the options [see the docstring of `format()`](https://github.com/cknd/stackprinter/blob/master/stackprinter/__init__.py#L28-L149).
100+
`format()`, `show()` and `set_excepthook()` accept a common set of keyword args. They allow you to tweak the formatting, hide certain variables by name, skip variables in calls within certain files, and some other stuff.
101101

102102
```python
103103
try:
@@ -108,8 +108,9 @@ except RuntimeError as exc:
108108
truncate_vals=9001,
109109
style="darkbg2")
110110
```
111+
For all the options [see the docstring of `format()`](https://github.com/cknd/stackprinter/blob/master/stackprinter/__init__.py#L28-L149).
111112

112-
### Integration with the standard `logging` module
113+
### Option 3: Integrate with the standard `logging` module
113114

114115
With a bit of extra plumbing you can log errors like this via the normal `logging` methods, without having to import `stackprinter` at the site of the logging call. So you can continue to write nice and simple error handlers like so...
115116

0 commit comments

Comments
 (0)