docs: add django usage example

This commit is contained in:
Kristofers Solo 2024-09-12 15:59:04 +03:00
parent 44ffa512a1
commit 5ccd804b9b

View File

@ -5,6 +5,7 @@
- [Description](#description) - [Description](#description)
- [Installation](#installation) - [Installation](#installation)
- [Usage](#usage) - [Usage](#usage)
* [Django](#django)
- [Examples](#examples) - [Examples](#examples)
* [Basic Logging](#basic-logging) * [Basic Logging](#basic-logging)
* [Error Logging with Exception](#error-logging-with-exception) * [Error Logging with Exception](#error-logging-with-exception)
@ -66,6 +67,42 @@ logger.error("This is an error message")
logger.critical("This is a critical message") logger.critical("This is a critical message")
``` ```
### Django
In your Django project's `settings.py` file, add the following logging configuration:
```python
LOGGING = {
"version": 1,
"disable_existing_loggers": False,
"formatters": {
"bunyan": {
"()": BunyanFormatter,
"project_name": "cashflow",
"project_root": BASE_DIR,
},
},
"handlers": {
"console": {
"level": "DEBUG",
"class": "logging.StreamHandler",
"formatter": "bunyan",
"stream": "ext://sys.stdout",
},
"file": {
"level": "DEBUG",
"class": "logging.FileHandler",
"filename": BASE_DIR / "logs" / "django.log",
"formatter": "bunyan",
},
},
"root": {
"level": "DEBUG",
"handlers": ["console", "file"],
},
}
```
## Examples ## Examples
### Basic Logging ### Basic Logging