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
This commit introduces a new Styling Guide to the project documentation.
The guide (`docs/styling_guide.md`) is generated based on an analysis
of the project's existing linter (Pylint) and formatter (Black)
configurations (`pylintrc`, `pyproject.toml`) as well as Mypy settings.
It summarizes key conventions, including:
- Code formatting with Black (100-char line length).
- Naming conventions (snake_case, PascalCase, etc.).
- Indentation (4 spaces) and line endings (LF).
- Docstring expectations.
- Type checking enforcement with Mypy.
The new guide has been linked from the Contributing page
(`docs/contributing.md`) and added to the site navigation
in `mkdocs.yml`.
Copy file name to clipboardExpand all lines: docs/contributing.md
+6-2Lines changed: 6 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -25,7 +25,7 @@ The following are things that can be worked on without an existing issue:
25
25
26
26
### 2. Fork the repository and make your changes
27
27
28
-
We don't have styling documentation, so where possible try to match existing code. This includes the use of "headings" and "dividers" (this will make sense when you look at the code).
28
+
Code style is enforced using `black` for formatting, `pylint` for linting, and `mypy` for type checking. Please ensure your changes pass these checks. For a summary of the main conventions, see the [Styling Guide](styling_guide.md). Otherwise, try to match existing code. This includes the use of "headings" and "dividers" (this will make sense when you look at the code).
29
29
30
30
All devlopment tooling can be installed (usually into a virtual environment), using the `dev` optional dependency:
31
31
@@ -47,10 +47,14 @@ mypy src tests
47
47
pytest
48
48
```
49
49
50
-
If making changes to the documentation you can preview the changes locally using `mkdocs`. Changes to the README can be previewed using [`grip`](https://github.com/joeyespo/grip) (not included in `dev` dependencies).
50
+
The above commands (`black`, `pylint`, `mypy`, `pytest`) should all be run before submitting a pull request.
51
+
52
+
If making changes to the documentation you can preview the changes locally using `mkdocs`. Changes to the `README.md` can be previewed using a tool like [`grip`](https://github.com/joeyespo/grip) (installable via `pip install grip`).
Copy file name to clipboardExpand all lines: docs/cookbook.md
+6-4Lines changed: 6 additions & 4 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -32,7 +32,7 @@ You can modify the `dict` of data that will be logged by overriding the `process
32
32
33
33
```python
34
34
classSillyFormatter(JsonFormatter):
35
-
defprocess_log_record(log_record):
35
+
defprocess_log_record(self, log_record):
36
36
new_record = {k[::-1]: v for k, v in log_record.items()}
37
37
return new_record
38
38
```
@@ -92,7 +92,7 @@ def generate_request_id():
92
92
93
93
classRequestIdFilter(logging.Filter):
94
94
deffilter(self, record):
95
-
record.record_id= get_request_id()
95
+
record.request_id= get_request_id()# Add request_id to the LogRecord
96
96
returnTrue
97
97
98
98
request_id_filter = RequestIdFilter()
@@ -137,9 +137,11 @@ def main_3():
137
137
main_3()
138
138
```
139
139
140
-
## Using `fileConfig`
140
+
## Using Dictionary-based Configuration (e.g., from YAML)
141
+
142
+
While Python's [`logging.config.fileConfig`](https://docs.python.org/3/library/logging.config.html#logging.config.fileConfig) is designed for INI-style configuration files, [`logging.config.dictConfig`](https://docs.python.org/3/library/logging.config.html#logging.config.dictConfig) is used for dictionary-based configurations, often loaded from YAML or JSON files.
141
143
142
-
To use the module with a yaml config file using the [`fileConfig` function](https://docs.python.org/3/library/logging.config.html#logging.config.fileConfig), use the class `pythonjsonlogger.json.JsonFormatter`. Here is a sample config file:
144
+
To use `python-json-logger`with such a configuration, you specify the formatter class (e.g., `pythonjsonlogger.json.JsonFormatter`) in your dictionary. Here is a sample configuration loaded from a YAML file:
Copy file name to clipboardExpand all lines: docs/index.md
+25-15Lines changed: 25 additions & 15 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -23,43 +23,53 @@ This library assumes that you are famliar with the `logging` standard library pa
23
23
-**Fully Customizable Output Fields:** Control required, excluded, and static fields including automatically picking up custom attributes on `LogRecord` objects. Fields can be renamed before they are output.
24
24
-**Encode Any Type:** Encoders are customized to ensure that something sane is logged for any input including those that aren't supported by default. For example formatting UUID objects into their string representation and bytes objects into a base 64 encoded string.
25
25
26
-
## Quick Start
26
+
## Getting Started
27
27
28
-
Follow our [Quickstart Guide](quickstart.md).
28
+
Jump right in with our [Quickstart Guide](quickstart.md) to get `python-json-logger` integrated into your project quickly.
29
29
30
-
```python title="TLDR"
30
+
Here's a small taste of what it looks like:
31
+
32
+
```python title="Example Usage"
31
33
import logging
32
34
from pythonjsonlogger.json import JsonFormatter
33
35
34
36
logger = logging.getLogger()
35
37
logger.setLevel(logging.INFO)
36
38
37
39
handler = logging.StreamHandler()
40
+
# Note: The JsonFormatter class is available from pythonjsonlogger.json,
41
+
# pythonjsonlogger.orjson, and pythonjsonlogger.msgspec
38
42
handler.setFormatter(JsonFormatter())
39
43
40
44
logger.addHandler(handler)
41
45
42
-
logger.info("Logging using pythonjsonlogger!", extra={"more_data": True})
43
-
44
-
# {"message": "Logging using pythonjsonlogger!", "more_data": true}
46
+
logger.info("Logging using python-json-logger!", extra={"more_data": True})
47
+
# Expected output:
48
+
# {"message": "Logging using python-json-logger!", "more_data": true}
45
49
```
46
50
51
+
## Where to Go Next
47
52
48
-
## Bugs, Feature Requests etc
49
-
Please [submit an issue on github](https://github.com/nhairs/python-json-logger/issues).
53
+
***[Quickstart Guide](quickstart.md):** For installation and basic setup.
54
+
***[Cookbook](cookbook.md):** For more advanced usage patterns and recipes.
55
+
***API Reference:** Dive into the details of specific formatters, functions, and classes (see navigation menu).
56
+
***[Contributing Guidelines](contributing.md):** If you'd like to contribute to the project.
57
+
***[Changelog](changelog.md):** To see what's new in recent versions.
50
58
51
-
In the case of bug reports, please help us help you by following best practices [^1^](https://marker.io/blog/write-bug-report/) [^2^](https://www.chiark.greenend.org.uk/~sgtatham/bugs.html).
59
+
## Project Information
52
60
53
-
In the case of feature requests, please provide background to the problem you are trying to solve so that we can a solution that makes the most sense for the library as well as your use case.
61
+
### Bugs, Feature Requests, etc.
62
+
Please [submit an issue on GitHub](https://github.com/nhairs/python-json-logger/issues).
54
63
55
-
## License
64
+
In the case of bug reports, please help us help you by following best practices [^1^](https://marker.io/blog/write-bug-report/) [^2^](https://www.chiark.greenend.org.uk/~sgtatham/bugs.html).
56
65
57
-
This project is licensed under the BSD 2 Clause License - see [`LICENSE`](https://github.com/nhairs/python-json-logger/blob/main/LICENSE)
66
+
In the case of feature requests, please provide background to the problem you are trying to solve so that we can find a solution that makes the most sense for the library as well as your use case.
58
67
59
-
## Authors and Maintainers
68
+
### License
69
+
This project is licensed under the BSD 2 Clause License - see the [LICENSE file](https://github.com/nhairs/python-json-logger/blob/main/LICENSE) on GitHub.
60
70
61
-
This project was originally authored by [Zakaria Zajac](https://github.com/madzak) and our wonderful [contributors](https://github.com/nhairs/python-json-logger/graphs/contributors)
71
+
### Authors and Maintainers
72
+
This project was originally authored by [Zakaria Zajac](https://github.com/madzak) and our wonderful [contributors](https://github.com/nhairs/python-json-logger/graphs/contributors).
0 commit comments