Skip to content

Commit 84d79fa

Browse files
committed
Fix middleware handling to skip logging for static and media file requests
fixes #91
1 parent 0ec54c8 commit 84d79fa

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

drf_api_logger/middleware/api_logger_middleware.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,16 @@ def __init__(self, get_response):
8484
if type(settings.DRF_API_LOGGER_MAX_RESPONSE_BODY_SIZE) is int:
8585
self.DRF_API_LOGGER_MAX_RESPONSE_BODY_SIZE = settings.DRF_API_LOGGER_MAX_RESPONSE_BODY_SIZE
8686

87+
def is_static_or_media_request(self, path):
88+
static_url = getattr(settings, 'STATIC_URL', '/static/')
89+
media_url = getattr(settings, 'MEDIA_URL', '/media/')
90+
91+
return path.startswith(static_url) or path.startswith(media_url)
92+
8793
def __call__(self, request):
94+
# Skip logging for static and media files
95+
if self.is_static_or_media_request(request.path):
96+
return self.get_response(request)
8897

8998
# Run only if logger is enabled.
9099
if self.DRF_API_LOGGER_DATABASE or self.DRF_API_LOGGER_SIGNAL:

0 commit comments

Comments
 (0)