Name | easy-audit-logging JSON |
Version |
0.1.31
JSON |
| download |
home_page | None |
Summary | A Django package for easy CRUD operation logging and container logs |
upload_time | 2025-08-17 08:55:51 |
maintainer | None |
docs_url | None |
author | None |
requires_python | >=3.8 |
license | MIT |
keywords |
audit
django
logging
utilities
|
VCS |
 |
bugtrack_url |
|
requirements |
No requirements were recorded.
|
Travis-CI |
No Travis.
|
coveralls test coverage |
No coveralls.
|
# Easy Audit Logging
A Django package that extends the default logging mechanism to track CRUD operations and container logs.
## Features
- Automatic logging of CRUD operations (Create, Read, Update, Delete)
- Tracks both HTTP requests and model changes
- Custom log levels Audit(21) and API(22) for CRUD and Request-Response auditing.
- Structured JSON logs for audit trails
- Human-readable container logs
- Separate log files for audit and container logs
- Console and file output options
## Installation
1. Install the package:
```bash
pip install easy-audit-logging
```
2. Add 'easy_audit_logging' to your INSTALLED_APPS in settings.py:
```python
INSTALLED_APPS = [
...
'easy_audit_logging',
]
```
3. Add the middleware to your MIDDLEWARE in settings.py:
```python
MIDDLEWARE = [
...
'easy_audit_logging.middleware.EasyLoggingMiddleware',
]
```
4. Configure logging in settings.py:
```python
from easy_audit_logging import *
LOGGING = {
"version": 1,
"disable_existing_loggers": False,
"formatters": {
"json": get_json_formatter(),
"verbose": get_console_formatter(),
"api_json": get_api_file_formatter(),
},
"handlers": {
"console": {
"level": "DEBUG",
"class": "logging.StreamHandler",
"formatter": "verbose",
},
"file": get_json_handler(level="DEBUG", formatter="json"),
"api_file": get_api_file_handler(formatter="api_json"),
},
"root": {"level": "DEBUG", "handlers": ["console", "file"]},
"loggers": {
"audit.request": {
"handlers": ["api_file"],
"level": "API",
"propagate": False,
},
"django": {
"handlers": ["console", "file"],
"level": "INFO",
"propagate": False,
},
}
}
```
5. For external services logging, extend ```HTTPClient or SFTPClient```
```python
class ExternalService(HTTPClient):
def __init__(self):
super().__init__("service_name")
def connect(self):
url = "https://www.sample.com"
response = self.get(url) # sample log structure below
```
7. Create ```audit_logs``` folder in project directory
## Log Types
### Container Logs
#### Console Log Format
```shell
'%(levelname)s %(asctime)s %(pathname)s %(module)s %(funcName)s %(message)s'
-----------------------------------------------------------------------------
INFO 2025-04-30 08:51:10,403 /app/patients/api/utils.py utils create_patient_with_contacts_and_diseases Patient 'd6c9a056-0b57-453a-8c0f-44319004b761 - Patient3' created.
```
#### File Log Format
```json
{
"timestamp": "2025-05-15 13:38:02.141",
"level": "DEBUG",
"name": "botocore.auth",
"path": "/opt/venv/lib/python3.11/site-packages/botocore/auth.py",
"module": "auth",
"function": "add_auth",
"message": "Calculating signature using v4 auth.",
"exception": "",
"request": "",
"extra_fields": ""
}
```
### Request-Response Log
#### Incoming Log Format
```json
{
"timestamp": "2025-05-19 15:25:27.836",
"level": "API",
"name": "audit.request",
"message": "Audit Internal Request",
"service_name": "review_board",
"request_type": "internal",
"protocol": "http",
"request_repr": {
"method": "GET",
"path": "/api/v1/health/",
"query_params": {},
"headers": {
"Content-Type": "application/json",
},
"user": null,
"body": {
"title": "hello"
}
},
"response_repr": {
"status_code": 200,
"headers": {
"Content-Type": "application/json",
},
"body": {
"status": "ok"
}
},
"error_message": null,
"execution_time": 5.376734018325806
}
```
#### External Log format
```json
{
"timestamp": "2025-05-19 15:25:27.717",
"level": "API",
"name": "audit.request",
"message": "Audit External Service",
"service_name": "apollo",
"request_type": "external",
"protocol": "http",
"request_repr": "{'endpoint': 'https://www.sample.com', 'method': 'GET', 'headers': {}, 'body': {}}",
"response_repr": "{'status_code': 200, 'body': {'title': 'title', 'expiresIn': 3600, 'error': None, 'errorDescription': None}}",
"error_message": "",
"execution_time": 5.16809344291687
}
```
## License
This project is licensed under the MIT License - see the LICENSE file for details.
Raw data
{
"_id": null,
"home_page": null,
"name": "easy-audit-logging",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.8",
"maintainer_email": null,
"keywords": "audit, django, logging, utilities",
"author": null,
"author_email": "Shreeshan <shreeshan256@gmail.com>",
"download_url": "https://files.pythonhosted.org/packages/66/cd/6ad5c74de17cb38cef1ef82609d6483a0aa2e93314e9a5372c137c2578f9/easy_audit_logging-0.1.31.tar.gz",
"platform": null,
"description": "# Easy Audit Logging\n\nA Django package that extends the default logging mechanism to track CRUD operations and container logs.\n\n## Features\n\n- Automatic logging of CRUD operations (Create, Read, Update, Delete)\n- Tracks both HTTP requests and model changes\n- Custom log levels Audit(21) and API(22) for CRUD and Request-Response auditing.\n- Structured JSON logs for audit trails\n- Human-readable container logs\n- Separate log files for audit and container logs\n- Console and file output options\n\n## Installation\n\n1. Install the package:\n```bash\npip install easy-audit-logging\n```\n\n2. Add 'easy_audit_logging' to your INSTALLED_APPS in settings.py:\n```python\nINSTALLED_APPS = [\n ...\n 'easy_audit_logging',\n]\n```\n\n3. Add the middleware to your MIDDLEWARE in settings.py:\n```python\nMIDDLEWARE = [\n ...\n 'easy_audit_logging.middleware.EasyLoggingMiddleware',\n]\n```\n\n4. Configure logging in settings.py:\n```python\nfrom easy_audit_logging import *\n\nLOGGING = {\n \"version\": 1,\n \"disable_existing_loggers\": False,\n \"formatters\": {\n \"json\": get_json_formatter(),\n \"verbose\": get_console_formatter(),\n \"api_json\": get_api_file_formatter(),\n },\n \"handlers\": {\n \"console\": {\n \"level\": \"DEBUG\",\n \"class\": \"logging.StreamHandler\",\n \"formatter\": \"verbose\",\n },\n \"file\": get_json_handler(level=\"DEBUG\", formatter=\"json\"),\n \"api_file\": get_api_file_handler(formatter=\"api_json\"),\n },\n \"root\": {\"level\": \"DEBUG\", \"handlers\": [\"console\", \"file\"]},\n \"loggers\": {\n \"audit.request\": {\n \"handlers\": [\"api_file\"],\n \"level\": \"API\",\n \"propagate\": False,\n },\n \"django\": {\n \"handlers\": [\"console\", \"file\"],\n \"level\": \"INFO\",\n \"propagate\": False,\n },\n }\n}\n```\n\n5. For external services logging, extend ```HTTPClient or SFTPClient```\n```python\nclass ExternalService(HTTPClient):\n def __init__(self):\n super().__init__(\"service_name\")\n\n def connect(self):\n url = \"https://www.sample.com\"\n response = self.get(url) # sample log structure below\n```\n\n7. Create ```audit_logs``` folder in project directory\n\n## Log Types\n\n### Container Logs\n#### Console Log Format\n```shell\n'%(levelname)s %(asctime)s %(pathname)s %(module)s %(funcName)s %(message)s'\n-----------------------------------------------------------------------------\nINFO 2025-04-30 08:51:10,403 /app/patients/api/utils.py utils create_patient_with_contacts_and_diseases Patient 'd6c9a056-0b57-453a-8c0f-44319004b761 - Patient3' created.\n```\n\n#### File Log Format\n```json\n{\n \"timestamp\": \"2025-05-15 13:38:02.141\",\n \"level\": \"DEBUG\",\n \"name\": \"botocore.auth\",\n \"path\": \"/opt/venv/lib/python3.11/site-packages/botocore/auth.py\",\n \"module\": \"auth\",\n \"function\": \"add_auth\",\n \"message\": \"Calculating signature using v4 auth.\",\n \"exception\": \"\",\n \"request\": \"\",\n \"extra_fields\": \"\"\n}\n```\n\n### Request-Response Log\n#### Incoming Log Format\n```json\n{\n \"timestamp\": \"2025-05-19 15:25:27.836\",\n \"level\": \"API\",\n \"name\": \"audit.request\",\n \"message\": \"Audit Internal Request\",\n \"service_name\": \"review_board\",\n \"request_type\": \"internal\",\n \"protocol\": \"http\",\n \"request_repr\": {\n \"method\": \"GET\",\n \"path\": \"/api/v1/health/\",\n \"query_params\": {},\n \"headers\": {\n \"Content-Type\": \"application/json\",\n },\n \"user\": null,\n \"body\": {\n \"title\": \"hello\"\n }\n },\n \"response_repr\": {\n \"status_code\": 200,\n \"headers\": {\n \"Content-Type\": \"application/json\",\n },\n \"body\": {\n \"status\": \"ok\"\n }\n },\n \"error_message\": null,\n \"execution_time\": 5.376734018325806\n}\n```\n\n#### External Log format\n```json\n{\n \"timestamp\": \"2025-05-19 15:25:27.717\",\n \"level\": \"API\",\n \"name\": \"audit.request\",\n \"message\": \"Audit External Service\",\n \"service_name\": \"apollo\",\n \"request_type\": \"external\",\n \"protocol\": \"http\",\n \"request_repr\": \"{'endpoint': 'https://www.sample.com', 'method': 'GET', 'headers': {}, 'body': {}}\",\n \"response_repr\": \"{'status_code': 200, 'body': {'title': 'title', 'expiresIn': 3600, 'error': None, 'errorDescription': None}}\",\n \"error_message\": \"\",\n \"execution_time\": 5.16809344291687\n}\n```\n\n## License\n\nThis project is licensed under the MIT License - see the LICENSE file for details.\n",
"bugtrack_url": null,
"license": "MIT",
"summary": "A Django package for easy CRUD operation logging and container logs",
"version": "0.1.31",
"project_urls": {
"Documentation": "https://github.com/shree256/easy-audit-logging",
"Homepage": "https://github.com/shree256/easy-audit-logging",
"Repository": "https://github.com/shree256/easy-audit-logging"
},
"split_keywords": [
"audit",
" django",
" logging",
" utilities"
],
"urls": [
{
"comment_text": null,
"digests": {
"blake2b_256": "66ee7888aa8e160478348ad6ccbe6450d30ff8ef835ee87cabe909cd2c35865d",
"md5": "9f6f2e7f5ce112eec38b6e3eae14156d",
"sha256": "fc01fd8368020c423754dc42d0e99e3183e28cde5c439b22d24defd689343356"
},
"downloads": -1,
"filename": "easy_audit_logging-0.1.31-py3-none-any.whl",
"has_sig": false,
"md5_digest": "9f6f2e7f5ce112eec38b6e3eae14156d",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.8",
"size": 14659,
"upload_time": "2025-08-17T08:55:53",
"upload_time_iso_8601": "2025-08-17T08:55:53.321671Z",
"url": "https://files.pythonhosted.org/packages/66/ee/7888aa8e160478348ad6ccbe6450d30ff8ef835ee87cabe909cd2c35865d/easy_audit_logging-0.1.31-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": null,
"digests": {
"blake2b_256": "66cd6ad5c74de17cb38cef1ef82609d6483a0aa2e93314e9a5372c137c2578f9",
"md5": "74a4f59209a98ef583e9d6d5da870df7",
"sha256": "d94a703679e8b16eae344fdce99fd60f57f3f956baade0c4ab2d5de256ee63f7"
},
"downloads": -1,
"filename": "easy_audit_logging-0.1.31.tar.gz",
"has_sig": false,
"md5_digest": "74a4f59209a98ef583e9d6d5da870df7",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.8",
"size": 12909,
"upload_time": "2025-08-17T08:55:51",
"upload_time_iso_8601": "2025-08-17T08:55:51.978811Z",
"url": "https://files.pythonhosted.org/packages/66/cd/6ad5c74de17cb38cef1ef82609d6483a0aa2e93314e9a5372c137c2578f9/easy_audit_logging-0.1.31.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2025-08-17 08:55:51",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "shree256",
"github_project": "easy-audit-logging",
"travis_ci": false,
"coveralls": false,
"github_actions": false,
"lcname": "easy-audit-logging"
}