Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/tarsil/django-loguru
A middleware to log the requests and responses using loguru.
https://github.com/tarsil/django-loguru
Last synced: 4 days ago
JSON representation
A middleware to log the requests and responses using loguru.
- Host: GitHub
- URL: https://github.com/tarsil/django-loguru
- Owner: tarsil
- License: mit
- Created: 2021-11-29T14:24:04.000Z (almost 3 years ago)
- Default Branch: main
- Last Pushed: 2022-05-23T15:41:31.000Z (over 2 years ago)
- Last Synced: 2024-10-08T06:50:39.339Z (about 1 month ago)
- Language: Python
- Size: 537 KB
- Stars: 10
- Watchers: 2
- Forks: 1
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- Funding: .github/FUNDING.yml
- License: LICENSE
Awesome Lists containing this project
README
# Django Loguru
The extension was based on another one and added some extra flavours.
One of the biggest problems with the apps is the logging and that can be messy sometimes.Since this serves as a middleware, it only depends on django (including django rest framework).
Documentation: https://tarsil.github.io/django-loguru/
## Table of Contents
---
1. [Requirements](#requirements)
2. [Installation](#installation)
3. [Settings](#settings)
4. [License](#license)---
## Requirements
1. Python >= 3.7
2. [Django](https://www.djangoproject.com/) >= 3.1## Installation
- `pip install django-loguru`
- Add `django_loguru` to `INSTALLED_APPS` settings.```python
INSTALLED_APPS = [
...
'django_loguru'
]
```- Add `DJANGO_LOGURU_MIDDLEWARE` to your settings.
```python
DJANGO_LOGGING_MIDDLEWARE = {
'DEFAULT_FORMAT': True,
'MESSAGE_FORMAT': "{time} {message}",
'LOG_USER': False
}
```- Add `django_loguru.middleware.DjangoLoguruMiddleware` as the very last in the list of `MIDDLEWARE`.
The logs should be now activated for every request/response of you application.
If you desire to override what is shown on the screen.
```python
from django_loguru.middleware import DjangoLoguruMiddlewareclass MyCustomMiddleware(DjangoLoguruMiddleware):
def __call__(self, request):
"""
Code to be executed on every request/response call.
"""
logger.info(f"URL: {request.get_raw_uri()}")
logger.info(f"Method: {request.method}")
...
...```
## Settings
1. `DEFAULT_FORMAT` - Default `True` and it will use the default `MESSAGE_FORMAT`.
2. `MESSAGE_FORMAT` - Sets the format of the log messages. Defaults to
`{time} {message}`. More information about
your options on [loguru](https://loguru.readthedocs.io/en/stable/api/logger.html#color) docs.
3. `LOG_POST` - Default to `False` and it won't show POST data.
4. `LOG_PUT` - Default to `False` and it won't show PUT data.
5. `LOG_PATCH` - Default to `False` and it won't show PATCH data.
6. `LOG_DELETE` - Default to `False` and it won't show DELETE data.
7. `LOG_USER` - Default to `True` and tells which user did the request/response.## License
MIT-License