diff --git a/drf_api_logger/middleware/api_logger_middleware.py b/drf_api_logger/middleware/api_logger_middleware.py index bc1f244..b461c6c 100644 --- a/drf_api_logger/middleware/api_logger_middleware.py +++ b/drf_api_logger/middleware/api_logger_middleware.py @@ -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: @@ -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 @@ -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())