Skip to content

Commit f55300d

Browse files
committed
Update readme
1 parent cc6cd75 commit f55300d

1 file changed

Lines changed: 10 additions & 7 deletions

File tree

README.md

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -107,17 +107,13 @@ except RuntimeError as exc:
107107
truncate_vals=9001)
108108
```
109109

110-
111-
It's also possible to integrate this neatly with standard logging calls through a bit of extra plumbing. The goal is to use `logging` calls from the standard library without explicitly importing `stackprinter` at the site of the logging call...
110+
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...
112111
```python
113-
logger = logging.getLogger("some_logger")
114-
115112
try:
116113
nothing = {}
117114
dangerous_function(nothing.get("something"))
118115
except:
119116
logger.exception('My hovercraft is full of eels.')
120-
121117
```
122118
...but getting an annotated traceback in the resulting log, still.
123119
```
@@ -141,10 +137,10 @@ except:
141137
┆ TypeError: unsupported operand type(s) for +: 'NoneType' and 'int'
142138
```
143139

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 before using it.
140+
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:
145141

146142
```python
147-
# Logging setup
143+
# Set up logging
148144
import logging
149145
import stackprinter
150146

@@ -168,6 +164,13 @@ def configure_logger(logger_name=None):
168164
logger.addHandler(handler)
169165

170166
configure_logger("some_logger")
167+
168+
# Use it
169+
logger = logging.getLogger("some_logger")
170+
try:
171+
something()
172+
except:
173+
logger.exception("message")
171174
```
172175
See [demo_logging.py](https://github.com/cknd/stackprinter/blob/master/demo_logging.py) for a runnable example.
173176

0 commit comments

Comments
 (0)