You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
closes#24
Uses `defaults` argument to prepopulate fields on records.
### Test Plan
Unit tests
---------
Co-authored-by: Nicholas Hairs <info@nicholashairs.com>
Copy file name to clipboardExpand all lines: docs/changelog.md
+1Lines changed: 1 addition & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
9
9
### Changed
10
10
-`pythonjsonlogger.[ORJSON,MSGSPEC]_AVAILABLE` no longer imports the respective package when determining availability.
11
11
-`pythonjsonlogger.[orjson,msgspec]` now throws a `pythonjsonlogger.exception.MissingPackageError` when required libraries are not available. These contain more information about what is missing whilst still being an `ImportError`.
12
+
-`defaults` parameter is no longer ignored and now conforms to the standard library. Setting a defaults dictionary will add the specified keys if the those keys do not exist in a record or weren't passed by the `extra` parameter when logging a message.
Copy file name to clipboardExpand all lines: docs/quickstart.md
+12Lines changed: 12 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -78,6 +78,18 @@ logger.info(
78
78
79
79
Finally, any non-standard attributes added to a `LogRecord` will also be included in the logged data. See [Cookbook: Request / Trace IDs](cookbook.md#request-trace-ids) for an example.
80
80
81
+
#### Default Fields
82
+
83
+
Default fields that are added to every log record prior to any other field can be set using the `default` argument.
84
+
85
+
```python
86
+
formatter = JsonFormatter(
87
+
defaults={"environment": "dev"}
88
+
)
89
+
# ...
90
+
logger.info("this overwrites the environment field", extras={"environment": "dev"})
91
+
```
92
+
81
93
#### Static Fields
82
94
83
95
Static fields that are added to every log record can be set using the `static_fields` argument.
0 commit comments