Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
vishalanandl177 committed Jul 28, 2024
2 parents 15ec845 + aa2d940 commit 09d38d2
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions drf_api_logger/middleware/api_logger_middleware.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,16 @@ def __init__(self, get_response):
if type(settings.DRF_API_LOGGER_MAX_RESPONSE_BODY_SIZE) is int:
self.DRF_API_LOGGER_MAX_RESPONSE_BODY_SIZE = settings.DRF_API_LOGGER_MAX_RESPONSE_BODY_SIZE

def is_static_or_media_request(self, path):
static_url = getattr(settings, 'STATIC_URL', '/static/')
media_url = getattr(settings, 'MEDIA_URL', '/media/')

return path.startswith(static_url) or path.startswith(media_url)

def __call__(self, request):
# Skip logging for static and media files
if self.is_static_or_media_request(request.path):
return self.get_response(request)

# Run only if logger is enabled.
if self.DRF_API_LOGGER_DATABASE or self.DRF_API_LOGGER_SIGNAL:
Expand Down Expand Up @@ -150,6 +159,7 @@ def __call__(self, request):
"application/vnd.api+json",
"application/gzip",
"application/octet-stream",
"text/calendar",
]
if hasattr(settings, "DRF_API_LOGGER_CONTENT_TYPES") and type(
settings.DRF_API_LOGGER_CONTENT_TYPES
Expand All @@ -165,6 +175,9 @@ def __call__(self, request):
response_body = '** Binary File **'
elif getattr(response, 'streaming', False):
response_body = '** Streaming **'
elif response.get('content-type') == 'text/calendar':
response_body = '** Calendar **'

else:
if type(response.content) is bytes:
response_body = json.loads(response.content.decode())
Expand Down

0 comments on commit 09d38d2

Please sign in to comment.