diff --git a/docs/contributing.md b/docs/contributing.md index 61ed3e0..41a45b8 100644 --- a/docs/contributing.md +++ b/docs/contributing.md @@ -25,7 +25,7 @@ The following are things that can be worked on without an existing issue: ### 2. Fork the repository and make your changes -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). +While there isn't extensive styling documentation, code style is enforced using `black` for formatting and `pylint` for linting (details below). Please ensure your changes pass these checks. Otherwise, try to match existing code. This includes the use of "headings" and "dividers" (this will make sense when you look at the code). All devlopment tooling can be installed (usually into a virtual environment), using the `dev` optional dependency: @@ -47,10 +47,14 @@ mypy src tests pytest ``` -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). +The above commands (`black`, `pylint`, `mypy`, `pytest`) should all be run before submitting a pull request. + +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`). ```shell mkdocs serve +# For README preview (after installing grip): +# grip ``` !!! note diff --git a/docs/cookbook.md b/docs/cookbook.md index c0755d5..4b747c5 100644 --- a/docs/cookbook.md +++ b/docs/cookbook.md @@ -32,7 +32,7 @@ You can modify the `dict` of data that will be logged by overriding the `process ```python class SillyFormatter(JsonFormatter): - def process_log_record(log_record): + def process_log_record(self, log_record): new_record = {k[::-1]: v for k, v in log_record.items()} return new_record ``` @@ -92,7 +92,7 @@ def generate_request_id(): class RequestIdFilter(logging.Filter): def filter(self, record): - record.record_id = get_request_id() + record.request_id = get_request_id() # Add request_id to the LogRecord return True request_id_filter = RequestIdFilter() diff --git a/docs/index.md b/docs/index.md index 6f15b2e..4c39bfb 100644 --- a/docs/index.md +++ b/docs/index.md @@ -23,11 +23,13 @@ This library assumes that you are famliar with the `logging` standard library pa - **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. - **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. -## Quick Start +## Getting Started -Follow our [Quickstart Guide](quickstart.md). +Jump right in with our [Quickstart Guide](quickstart.md) to get `python-json-logger` integrated into your project quickly. -```python title="TLDR" +Here's a small taste of what it looks like: + +```python title="Example Usage" import logging from pythonjsonlogger.json import JsonFormatter @@ -39,27 +41,32 @@ handler.setFormatter(JsonFormatter()) logger.addHandler(handler) -logger.info("Logging using pythonjsonlogger!", extra={"more_data": True}) - -# {"message": "Logging using pythonjsonlogger!", "more_data": true} +logger.info("Logging using python-json-logger!", extra={"more_data": True}) +# {"message": "Logging using python-json-logger!", "more_data": true} ``` +## Where to Go Next -## Bugs, Feature Requests etc -Please [submit an issue on github](https://github.com/nhairs/python-json-logger/issues). +* **[Quickstart Guide](quickstart.md):** For installation and basic setup. +* **[Cookbook](cookbook.md):** For more advanced usage patterns and recipes. +* **API Reference:** Dive into the details of specific formatters, functions, and classes (see navigation menu). +* **[Contributing Guidelines](contributing.md):** If you'd like to contribute to the project. +* **[Changelog](changelog.md):** To see what's new in recent versions. -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). +## Project Information -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. +### Bugs, Feature Requests, etc. +Please [submit an issue on GitHub](https://github.com/nhairs/python-json-logger/issues). -## License +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). -This project is licensed under the BSD 2 Clause License - see [`LICENSE`](https://github.com/nhairs/python-json-logger/blob/main/LICENSE) +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. -## Authors and Maintainers +### License +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. -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) +### Authors and Maintainers +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). It is currently maintained by: - - [Nicholas Hairs](https://github.com/nhairs) - [nicholashairs.com](https://www.nicholashairs.com) diff --git a/docs/quickstart.md b/docs/quickstart.md index 07486b1..3613aa4 100644 --- a/docs/quickstart.md +++ b/docs/quickstart.md @@ -89,7 +89,8 @@ formatter = JsonFormatter( defaults={"environment": "dev"} ) # ... -logger.info("this overwrites the environment field", extras={"environment": "dev"}) +logger.info("this message will have environment=dev by default") +logger.info("this overwrites the environment field", extra={"environment": "prod"}) ``` #### Static Fields