https://github.com/andrewpetrochenkov/django-exception.py
Django python exception model, admin, logging handler, middleware and excepthook
https://github.com/andrewpetrochenkov/django-exception.py
django error-handling exceptions logging
Last synced: about 1 month ago
JSON representation
Django python exception model, admin, logging handler, middleware and excepthook
- Host: GitHub
- URL: https://github.com/andrewpetrochenkov/django-exception.py
- Owner: andrewpetrochenkov
- License: unlicense
- Created: 2023-10-10T20:40:17.000Z (over 2 years ago)
- Default Branch: master
- Last Pushed: 2023-10-10T20:40:20.000Z (over 2 years ago)
- Last Synced: 2025-02-26T09:41:57.363Z (over 1 year ago)
- Topics: django, error-handling, exceptions, logging
- Language: Python
- Size: 4.88 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
### Installation
```bash
$ pip install django-exception
```
#### `settings.py`
```python
INSTALLED_APPS+=['django_exception']
```
#### `migrate`
```bash
$ python manage.py migrate
```
#### Models/tables
model|table|columns/fields
-|-|-
`ExceptionModel`|`django_exception`|id,module,filename,lineno,exc_type,exc_message,exc_traceback,timestamp
### Examples
`settings.py`
```python
LOGGING = {
"version": 1,
"handlers": {
"console": {
"level": "DEBUG",
"class": "logging.StreamHandler",
},
"django_exception": {
"level": "ERROR",
"class": "django_exception.ExceptionLogHandler",
}
},
"root": {
"handlers": ["console", "django_exception"],
"level": "DEBUG",
},
"loggers": {
"django_exception": {
"level": "ERROR",
"handlers": ["django_exception"],
"propagate": True,
},
},
}
MIDDLEWARE = [
"django_exception.middleware.ExceptionMiddleware",
]
```
`sys.excepthook` - log all exceptions
```python
import sys
import django_exception
def excepthook(exc_type, exc_message, tb):
django_exception.excepthook(exc_type, exc_message, tb)
raise exc_type(exc_message)
sys.excepthook = excepthook
```