Skip to content

Commit 2291a17

Browse files
Timezone aware "added_on" added in signals too.
1 parent a3f8d22 commit 2291a17

File tree

7 files changed

+14
-8
lines changed

7 files changed

+14
-8
lines changed

README.md

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# DRF API Logger
2-
![version](https://img.shields.io/badge/version-0.0.3-blue.svg)
2+
![version](https://img.shields.io/badge/version-0.0.4-blue.svg)
33

44
An API Logger for your Django Rest Framework project.
55

@@ -63,13 +63,17 @@ Log every request into the database.
6363
```python
6464
DRF_API_LOGGER_DATABASE = True # Default to False
6565
```
66-
Logs will be available in Django Admin Panel.
66+
* Logs will be available in Django Admin Panel.
67+
68+
* The search bar will search in Request Body, Response, Headers and API URL.
69+
70+
* You can also filter the logs based on the "added_on" date, Status Code and Request Methods.
6771

6872
![Alt text](https://raw.githubusercontent.com/vishalanandl177/DRF-API-Logger/master/logs.png?raw=true, "Logger")
6973

7074
![Alt text](https://raw.githubusercontent.com/vishalanandl177/DRF-API-Logger/master/lists.png?raw=true, "Lists")
7175

72-
![Alt text](https://raw.githubusercontent.com/vishalanandl177/DRF-API-Logger/master/details.png?raw=true, "Detais")
76+
![Alt text](https://raw.githubusercontent.com/vishalanandl177/DRF-API-Logger/master/details.png?raw=true, "Details")
7377

7478
Note: Make sure to migrate. It will create a table for logger if "DRF_API_LOGGER_DATABASE" is True else if already exists, it will delete the table.
7579

@@ -126,6 +130,7 @@ Specify interval (In Seconds).
126130
```python
127131
DRF_LOGGER_INTERVAL = 10 # In Seconds, Default to 10 seconds if not specified.
128132
```
133+
Note: The API call time (added_on) is timezone aware datetime object. It is actual time of API call irrespective of interval value or queue size.
129134
### Skip namespace
130135
You can skip the entire app to be logged into the database by specifying namespace of the app as list.
131136
```python

details.png

2.37 KB
Loading

drf_api_logger/admin.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ def added_on_time(self, obj):
1212
return obj.added_on.strftime("%d %b %Y %H:%M:%S")
1313

1414
added_on_time.admin_order_field = 'added_on'
15-
added_on_time.short_description = 'Time'
15+
added_on_time.short_description = 'Added On'
1616

1717
list_per_page = 20
1818
list_display = ('id', 'api', 'method', 'status_code', 'execution_time', 'added_on_time',)

drf_api_logger/middleware/api_logger_middleware.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import bleach
44
from django.conf import settings
55
from django.urls import resolve
6+
from django.utils import timezone
67

78
from drf_api_logger import API_LOGGER_SIGNAL
89
from drf_api_logger.start_logger_when_server_starts import LOGGER_THREAD
@@ -96,7 +97,8 @@ def __call__(self, request):
9697
client_ip_address=get_client_ip(request),
9798
response=response_body,
9899
status_code=response.status_code,
99-
execution_time=time.time() - start_time
100+
execution_time=time.time() - start_time,
101+
added_on=timezone.now()
100102
)
101103
if self.DRF_API_LOGGER_DATABASE:
102104
if LOGGER_THREAD:

drf_api_logger/models.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,7 @@
99
class BaseModel(models.Model):
1010
id = models.BigAutoField(primary_key=True)
1111

12-
# Auto add timestamp when created
13-
added_on = models.DateTimeField(null=True, auto_now_add=True)
12+
added_on = models.DateTimeField()
1413

1514
def __str__(self):
1615
return str(self.id)

lists.png

60.8 KB
Loading

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ def get_long_desc():
99

1010
setuptools.setup(
1111
name="drf_api_logger",
12-
version="0.0.3",
12+
version="0.0.4",
1313
author="Vishal Anand",
1414
author_email="vishalanandl177@gmail.com",
1515
description="An API Logger for your Django Rest Framework project.",

0 commit comments

Comments
 (0)