From 74bbecbd80732bda66cd8e974fe89db54ce7d2d8 Mon Sep 17 00:00:00 2001 From: chynybekov Date: Sun, 18 Sep 2022 02:31:41 +0530 Subject: [PATCH] 1. Changed request.path to request.path_info in middleware. 2. Deprecation warning for thread setName or getName. 3. Request twice when method not in DRF_API_LOGGER_METHODS. 4. Unicode Escape problem in headers, body and responses. --- README.md | 2 +- .../middleware/api_logger_middleware.py | 7 +++---- .../start_logger_when_server_starts.py | 5 +++-- requirements.txt | Bin 533 -> 1772 bytes setup.py | 2 +- 5 files changed, 8 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index c677ee8..af4f218 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@ # DRF API Logger -![version](https://img.shields.io/badge/version-1.1.10-blue.svg) +![version](https://img.shields.io/badge/version-1.1.11-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) diff --git a/drf_api_logger/middleware/api_logger_middleware.py b/drf_api_logger/middleware/api_logger_middleware.py index 0f8e289..715caec 100644 --- a/drf_api_logger/middleware/api_logger_middleware.py +++ b/drf_api_logger/middleware/api_logger_middleware.py @@ -1,6 +1,5 @@ import json import time -import bleach from django.conf import settings from django.urls import resolve from django.utils import timezone @@ -62,8 +61,8 @@ def __call__(self, request): # Run only if logger is enabled. if self.DRF_API_LOGGER_DATABASE or self.DRF_API_LOGGER_SIGNAL: - url_name = resolve(request.path).url_name - namespace = resolve(request.path).namespace + url_name = resolve(request.path_info).url_name + namespace = resolve(request.path_info).namespace # Always skip Admin panel if namespace == 'admin': @@ -100,7 +99,7 @@ def __call__(self, request): # 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) + return response if response.get('content-type') in ('application/json', 'application/vnd.api+json',): if getattr(response, 'streaming', False): diff --git a/drf_api_logger/start_logger_when_server_starts.py b/drf_api_logger/start_logger_when_server_starts.py index 013fd25..16c6244 100644 --- a/drf_api_logger/start_logger_when_server_starts.py +++ b/drf_api_logger/start_logger_when_server_starts.py @@ -11,12 +11,13 @@ already_exists = False for t in threading.enumerate(): - if t.getName() == LOG_THREAD_NAME: + if t.name == LOG_THREAD_NAME: already_exists = True + break if not already_exists: t = InsertLogIntoDatabase() t.daemon = True - t.setName(LOG_THREAD_NAME) + t.name = LOG_THREAD_NAME t.start() LOGGER_THREAD = t diff --git a/requirements.txt b/requirements.txt index da933bb31244ed983e4200b3da6001ee90e036f2..a65e13c3f52bc08997db07928048abb7024afe4a 100644 GIT binary patch literal 1772 zcmZ8i%Wm5+5ZrTteu@k~5~n%zP@u;K2#`~cvTQkyWl51_*v`kdo!KEpr4X1z+U4x* z?2!5UC%4}AcCgNNR@!$wE1TIp*3!P(7u#5cNN$C_dX$kl*21F&Vx0}xUt)3h6451| znLT>eUC1lPjD>$EPQ-WxerH=?4WDYv!(PREk7rg}gX|ObRH*sk3{;tj3AI6-nYrgO zgS_vs?gMUv$O$>MXLNS->dX>%_Fn+uW-XXC(1~a*l(>23%Dy2tslg6PJ44YOy14?i z8WA6mseZSvR%w}69bDNAs5xpxm8Iew*bmsXa=t(94LLPfG>*znQoq|tG(&|G5ZV2J zIy-QQZ&4|BD1E0p>4F}6%AniME{-B)=nS$+oit#4M*abv_G7OL=tu21&n)Obf6z&+ zFV?aClq)B?ab>tShl*4spY%&-i8s~YJPI(J;b(=vd)Hn}$dlRf@e#Fe$UnG(Qh^!N zLHa&9-Vyz@_8cZGrt&bILVc+2fZx=%!4o^D7Z&a>@oT`o1eUx)Bu$LUH2A&)6GpE< zARn@km$aXbDB#K5&nM?D)gYaZ$KbU=el$OfttvR>~jyVkjoGz zNX<0m$bF+YfuPUyis2 zBXObrbOjk_K8+f0oCTLuOec+B-!V^lT9xDo&5F$a&&kHAZm_Sy8&N;s2_5t*!F1cb0F`$N{r%##=;1xy#h$Z^^XsA5)xXP!NrxVNRpV5&mmKLZ z`JJbRcQ?;dL{9S%_Cev-Ns%Laog{rHO`4af_lyWZU rmD<+OfoDXXN3Cl<X5Z(#rIx?gV$-hcmc6QUfh+!jRBefE7%?ZmAhsz4Z1y^W5 zejMQ!Aa6k1lXGoqUXbBhdUrIGD`d$(+XRm z2u5C6e(?B|*K6`oJ~UK@3K0k{tZ+ft0$}yHktf3QMfX(?(^cB}a49J*11wY@Md88d zo7=VLFx02GgGVU$LX}Ry2lD^y@vpYu5n+EWHSJlq7UdaM{)&#*mUrB$swLG67iz0v ZrRk~KHw>`(6zGy#FUR`CoOuiL{{f@0pMwAZ diff --git a/setup.py b/setup.py index 1b36d08..24040d0 100644 --- a/setup.py +++ b/setup.py @@ -21,7 +21,7 @@ def get_long_desc(): setuptools.setup( name="drf_api_logger", - version="1.1.10", + version="1.1.11", author="Vishal Anand", author_email="vishalanandl177@gmail.com", description="An API Logger for your Django Rest Framework project.",