Skip to content

Commit 278952b

Browse files
committed
Update readme
1 parent 30e8e3b commit 278952b

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

README.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -111,15 +111,17 @@ except RuntimeError as exc:
111111

112112
### Integration with the standard `logging` module
113113

114-
It's also possible to integrate this neatly with standard logging calls through a bit of extra plumbing. The goal is to use the built in `logging` module's error handling method without explicitly importing `stackprinter` at the site of the logging call...
114+
Through a bit of extra plumbing you can log errors with normal `logging` methods, without having to import `stackprinter` at the site of the logging call. So you can continue to have nice and simple error handlers like this...
115+
115116
```python
117+
logger = logging.getLogger()
116118
try:
117119
nothing = {}
118120
dangerous_function(nothing.get("something"))
119121
except:
120122
logger.exception('My hovercraft is full of eels.')
121123
```
122-
...but getting an annotated traceback in the resulting log, still.
124+
...but still get annotated tracebacks in the resulting log.
123125
```
124126
2022-04-02 16:16:40,905 ERROR: My hovercraft is full of eels.
125127
┆ File "demo_logging.py", line 56, in <module>
@@ -141,7 +143,7 @@ except:
141143
┆ TypeError: unsupported operand type(s) for +: 'NoneType' and 'int'
142144
```
143145

144-
You can achieve this by adding a [custom formatter](https://docs.python.org/3/howto/logging-cookbook.html#customized-exception-formatting) to the logger beforehand:
146+
You get this by adding a [custom formatter](https://docs.python.org/3/howto/logging-cookbook.html#customized-exception-formatting) to the logger once before using it.
145147

146148
```python
147149
# Set up logging

0 commit comments

Comments
 (0)