Skip to content

Commit 67e0651

Browse files
committed
Update README with info about changes to version 5
Document the changes made with regards to logging the traceback.
1 parent a3d3b7f commit 67e0651

File tree

1 file changed

+42
-2
lines changed

1 file changed

+42
-2
lines changed

README.md

Lines changed: 42 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ All features can be fully configured from the configuration file.
1717

1818
**NOTE:** only python 3 is supported
1919

20-
:warning: **Version 3.x.x BREAKING CHANGES** see [Breaking Changes](#version-3xx-breaking-changes)
20+
:warning: **Version 5.x.x BREAKING CHANGES** see [Breaking Changes](#version-5xx-breaking-changes)
2121

2222
## Table of content
2323

@@ -67,7 +67,9 @@ All features can be fully configured from the configuration file.
6767
- [Case 7. Add all Log Extra as Dictionary to the Standard Formatter (including Django log extra)](#case-7-add-all-log-extra-as-dictionary-to-the-standard-formatter-including-django-log-extra)
6868
- [Case 8. Add Specific Log Extra to the Standard Formatter](#case-8-add-specific-log-extra-to-the-standard-formatter)
6969
- [Case 9. Django add request info to all log records](#case-9-django-add-request-info-to-all-log-records)
70+
- [Case 10. Add stack traces to log records](#case-10-add-stack-traces-to-log-records)
7071
- [Breaking Changes](#breaking-changes)
72+
- [Version 5.x.x Breaking Changes](#version-5xx-breaking-changes)
7173
- [Version 4.x.x Breaking Changes](#version-4xx-breaking-changes)
7274
- [Version 3.x.x Breaking Changes](#version-3xx-breaking-changes)
7375
- [Version 2.x.x Breaking Changes](#version-2xx-breaking-changes)
@@ -273,7 +275,7 @@ For more information on Pyramid Tweens see [Registering Tween](https://docs.pylo
273275

274276
## JSON Formatter
275277

276-
**JsonFormatter** is a python logging formatter that transform the log output into a json object.
278+
**JsonFormatter** is a python logging formatter that transforms the log output into a json object.
277279

278280
JSON log format is quite useful especially when the logs are sent to **LogStash**.
279281

@@ -1368,8 +1370,46 @@ handlers:
13681370
- request_fields
13691371
```
13701372
1373+
### Case 10. Add stack traces to log records
1374+
1375+
If you want to embed the stack trace of either an Exception or a log entry in general, you can do so with following additions to the logging call:
1376+
1377+
```python
1378+
import sys
1379+
1380+
logger.debug('My log with stack info', stack_info=True)
1381+
logger.critical('Exception happened', exc_info=sys.exc_info())
1382+
```
1383+
1384+
Or you simply call `logger.exception('Your message')` which automatically adds the exc_info. However this one is logging as in level `ERROR` and not `CRITICAL`.
1385+
1386+
This will make the stack info available for the formatter. It can be used for instance like follows:
1387+
1388+
```yaml
1389+
[...]
1390+
formatters:
1391+
json:
1392+
(): logging_utilities.formatters.json_formatter.JsonFormatter
1393+
fmt:
1394+
error:
1395+
stack_trace: exc_text
1396+
stack_info: stack_info
1397+
time: asctime
1398+
level: levelname
1399+
logger: name
1400+
module: module
1401+
message: message
1402+
request:
1403+
path: request.path
1404+
method: request.method
1405+
```
1406+
13711407
## Breaking Changes
13721408
1409+
### Version 5.x.x Breaking Changes
1410+
1411+
Previously, the fields `exc_text` and `stack_info` were always added to the log message if they existed. This behavior is slightly changed: instead of adding them to the message in any case, they are added to the record so that they can be configured via the `fmt` field in the logging configuration as described in [#case-10-add-stack-traces-to-log-records].
1412+
13731413
### Version 4.x.x Breaking Changes
13741414

13751415
From version 3.x.x to version 4.x.x there is the following breaking change:

0 commit comments

Comments
 (0)