Skip to content

KeyError when trying to delete an API Logger entry issu… #37

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 27, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
# DRF API Logger
![version](https://img.shields.io/badge/version-1.0.9-blue.svg)
![version](https://img.shields.io/badge/version-1.0.10-blue.svg)
[![Downloads](https://static.pepy.tech/personalized-badge/drf-api-logger?period=total&units=none&left_color=black&right_color=orange&left_text=Downloads%20Total)](http://pepy.tech/project/drf-api-logger)
[![Downloads](https://static.pepy.tech/personalized-badge/drf-api-logger?period=month&units=none&left_color=black&right_color=orange&left_text=Downloads%20Last%20Month)](https://pepy.tech/project/drf-api-logger)
[![Downloads](https://static.pepy.tech/personalized-badge/drf-api-logger?period=week&units=none&left_color=black&right_color=orange&left_text=Downloads%20Last%20Week)](https://pepy.tech/project/drf-api-logger)
[![Open Source](https://badges.frapsoft.com/os/v1/open-source.svg?v=103)](https://opensource.org/)
[![Donate](https://img.shields.io/badge/$-support-ff69b4.svg?style=flat)](https://paypal.me/chynybekov)

<a href="https://discord.gg/Kr8SbgPe"><img src="https://img.shields.io/badge/Discord-7289DA?style=for-the-badge&logo=discord&logoColor=white" alt="Join Community Badge"/></a>
<a href="https://discord.gg/eeYansFDCT"><img src="https://img.shields.io/badge/Discord-7289DA?style=for-the-badge&logo=discord&logoColor=white" alt="Join Community Badge"/></a>
<a href="https://www.instagram.com/coderssecret/"><img src="https://img.shields.io/badge/Instagram-E4405F?style=for-the-badge&logo=instagram&logoColor=white" alt="Join Instagram"/></a>
<a href="https://github.com/vishalanandl177"><img src="https://img.shields.io/badge/GitHub-100000?style=for-the-badge&logo=github&logoColor=white" alt="GitHub"/></a>

Expand Down Expand Up @@ -184,6 +184,12 @@ DRF_API_LOGGER_SLOW_API_ABOVE = 200 # Default to None
# Specify in milli-seconds.
```

### Want to log only selected request methods? (Optional)
You can log only selected methods by specifying `DRF_API_LOGGER_METHODS` in settings.py.
```python
DRF_API_LOGGER_METHODS = ['GET', 'POST', 'DELETE', 'PUT'] # Default to empty list (Log all the requests).
```

### Want to see the API information in local timezone? (Optional)
You can also identify slow APIs by specifying `DRF_API_LOGGER_TIMEDELTA` in settings.py.
It is going to display the API request time after adding the timedelta specified in the settings.py file.
Expand Down
5 changes: 4 additions & 1 deletion drf_api_logger/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,10 @@ def added_on_time(self, obj):

def changelist_view(self, request, extra_context=None):
response = super(APILogsAdmin, self).changelist_view(request, extra_context)
filtered_query_set = response.context_data["cl"].queryset
try:
filtered_query_set = response.context_data["cl"].queryset
except:
return response
analytics_model = filtered_query_set.values('added_on__date').annotate(total=Count('id')).order_by('total')
status_code_count_mode = filtered_query_set.values('id').values('status_code').annotate(
total=Count('id')).order_by('status_code')
Expand Down
11 changes: 11 additions & 0 deletions drf_api_logger/middleware/api_logger_middleware.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,12 @@ def __init__(self, get_response):
settings.DRF_API_LOGGER_SKIP_NAMESPACE) is list:
self.DRF_API_LOGGER_SKIP_NAMESPACE = settings.DRF_API_LOGGER_SKIP_NAMESPACE

self.DRF_API_LOGGER_METHODS = []
if hasattr(settings, 'DRF_API_LOGGER_METHODS'):
if type(settings.DRF_API_LOGGER_METHODS) is tuple or type(
settings.DRF_API_LOGGER_METHODS) is list:
self.DRF_API_LOGGER_METHODS = settings.DRF_API_LOGGER_METHODS

def __call__(self, request):

# Run only if logger is enabled.
Expand Down Expand Up @@ -81,6 +87,11 @@ def __call__(self, request):

headers = get_headers(request=request)
method = request.method

# Log only registered methods if available.
if len(self.DRF_API_LOGGER_METHODS) > 0 and method not in self.DRF_API_LOGGER_METHODS:
return self.get_response(request)

if response.get('content-type') in ('application/json', 'application/vnd.api+json',):
if getattr(response, 'streaming', False):
response_body = '** Streaming **'
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def get_long_desc():

setuptools.setup(
name="drf_api_logger",
version="1.0.9",
version="1.0.10",
author="Vishal Anand",
author_email="[email protected]",
description="An API Logger for your Django Rest Framework project.",
Expand Down