Skip to content

Commit

Permalink
<Vishal> Updated package name and minor changes.
Browse files Browse the repository at this point in the history
  • Loading branch information
vishalanandl177 committed Jul 28, 2024
1 parent 36bcd34 commit 15ec845
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 24 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# DRF API Logger
![version](https://img.shields.io/badge/version-1.1.15-blue.svg)
![version](https://img.shields.io/badge/version-1.1.16-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)
[![Open Source](https://badges.frapsoft.com/os/v1/open-source.svg?v=103)](https://opensource.org/)
Expand Down
10 changes: 5 additions & 5 deletions drf_api_logger/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def export_as_csv(self, request, queryset):

writer.writerow(field_names)
for obj in queryset:
row = writer.writerow([getattr(obj, field) for field in field_names])
writer.writerow([getattr(obj, field) for field in field_names])

return response

Expand All @@ -39,7 +39,7 @@ class SlowAPIsFilter(admin.SimpleListFilter):
def __init__(self, request, params, model, model_admin):
super().__init__(request, params, model, model_admin)
if hasattr(settings, 'DRF_API_LOGGER_SLOW_API_ABOVE'):
if type(settings.DRF_API_LOGGER_SLOW_API_ABOVE) == int: # Making sure for integer value.
if isinstance(settings.DRF_API_LOGGER_SLOW_API_ABOVE, int): # Making sure for integer value.
self._DRF_API_LOGGER_SLOW_API_ABOVE = settings.DRF_API_LOGGER_SLOW_API_ABOVE / 1000 # Converting to seconds.

def lookups(self, request, model_admin):
Expand Down Expand Up @@ -83,10 +83,10 @@ def __init__(self, model, admin_site):
super().__init__(model, admin_site)
self._DRF_API_LOGGER_TIMEDELTA = 0
if hasattr(settings, 'DRF_API_LOGGER_SLOW_API_ABOVE'):
if type(settings.DRF_API_LOGGER_SLOW_API_ABOVE) == int: # Making sure for integer value.
if isinstance(settings.DRF_API_LOGGER_SLOW_API_ABOVE, int): # Making sure for integer value.
self.list_filter += (SlowAPIsFilter,)
if hasattr(settings, 'DRF_API_LOGGER_TIMEDELTA'):
if type(settings.DRF_API_LOGGER_TIMEDELTA) == int: # Making sure for integer value.
if isinstance(settings.DRF_API_LOGGER_TIMEDELTA, int): # Making sure for integer value.
self._DRF_API_LOGGER_TIMEDELTA = settings.DRF_API_LOGGER_TIMEDELTA

def added_on_time(self, obj):
Expand All @@ -113,7 +113,7 @@ def changelist_view(self, request, extra_context=None):
response = super(APILogsAdmin, self).changelist_view(request, extra_context)
try:
filtered_query_set = response.context_data["cl"].queryset
except:
except Exception:
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(
Expand Down
2 changes: 1 addition & 1 deletion drf_api_logger/events.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def __init__(self, events=None):

try:
iter(events)
except:
except Exception:
raise AttributeError("type object %s is not iterable" %
(type(events)))
else:
Expand Down
22 changes: 8 additions & 14 deletions drf_api_logger/middleware/api_logger_middleware.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,6 @@
from drf_api_logger.start_logger_when_server_starts import LOGGER_THREAD
from drf_api_logger.utils import get_headers, get_client_ip, mask_sensitive_data

"""
File: api_logger_middleware.py
Class: APILoggerMiddleware
"""


class APILoggerMiddleware:
def __init__(self, get_response):
Expand Down Expand Up @@ -121,7 +116,7 @@ def __call__(self, request):
Ignore the request body if larger then specified.
"""
request_data = ''
except:
except Exception:
pass

tracing_id = None
Expand Down Expand Up @@ -198,14 +193,13 @@ def __call__(self, request):
execution_time=time.time() - start_time,
added_on=timezone.now()
)
if self.DRF_API_LOGGER_DATABASE:
if LOGGER_THREAD:
d = data.copy()
d['headers'] = json.dumps(d['headers'], indent=4, ensure_ascii=False) if d.get('headers') else ''
if request_data:
d['body'] = json.dumps(d['body'], indent=4, ensure_ascii=False) if d.get('body') else ''
d['response'] = json.dumps(d['response'], indent=4, ensure_ascii=False) if d.get('response') else ''
LOGGER_THREAD.put_log_data(data=d)
if self.DRF_API_LOGGER_DATABASE and LOGGER_THREAD:
d = data.copy()
d['headers'] = json.dumps(d['headers'], indent=4, ensure_ascii=False) if d.get('headers') else ''
if request_data:
d['body'] = json.dumps(d['body'], indent=4, ensure_ascii=False) if d.get('body') else ''
d['response'] = json.dumps(d['response'], indent=4, ensure_ascii=False) if d.get('response') else ''
LOGGER_THREAD.put_log_data(data=d)
if self.DRF_API_LOGGER_SIGNAL:
if tracing_id:
data.update({
Expand Down
2 changes: 1 addition & 1 deletion drf_api_logger/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def get_client_ip(request):
else:
ip = request.META.get('REMOTE_ADDR')
return ip
except:
except Exception:
return ''


Expand Down
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ def get_long_desc():


setuptools.setup(
name="drf_api_logger",
version="1.1.15",
name="drf-api-logger",
version="1.1.16",
author="Vishal Anand",
author_email="vishalanandl177@gmail.com",
description="An API Logger for your Django Rest Framework project.",
Expand Down

0 comments on commit 15ec845

Please sign in to comment.