mirror of
https://github.com/kristoferssolo/bunyan-formatter.git
synced 2025-10-21 17:20:35 +00:00
docs: add django usage example
This commit is contained in:
parent
44ffa512a1
commit
5ccd804b9b
37
README.md
37
README.md
@ -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
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user