File tree Expand file tree Collapse file tree 1 file changed +10
-0
lines changed
drf_api_logger/middleware Expand file tree Collapse file tree 1 file changed +10
-0
lines changed Original file line number Diff line number Diff line change @@ -51,6 +51,12 @@ def __init__(self, get_response):
5151 settings .DRF_API_LOGGER_METHODS ) is list :
5252 self .DRF_API_LOGGER_METHODS = settings .DRF_API_LOGGER_METHODS
5353
54+ self .DRF_API_LOGGER_STATUS_CODES = []
55+ if hasattr (settings , 'DRF_API_LOGGER_STATUS_CODES' ):
56+ if type (settings .DRF_API_LOGGER_STATUS_CODES ) is tuple or type (
57+ settings .DRF_API_LOGGER_STATUS_CODES ) is list :
58+ self .DRF_API_LOGGER_STATUS_CODES = settings .DRF_API_LOGGER_STATUS_CODES
59+
5460 def __call__ (self , request ):
5561
5662 # Run only if logger is enabled.
@@ -82,6 +88,10 @@ def __call__(self, request):
8288 # the view (and later middleware) are called.
8389 response = self .get_response (request )
8490
91+ # Only log required status codes if matching
92+ if self .DRF_API_LOGGER_STATUS_CODES and response .status_code not in self .DRF_API_LOGGER_STATUS_CODES :
93+ return response
94+
8595 # Code to be executed for each request/response after
8696 # the view is called.
8797
You can’t perform that action at this time.
0 commit comments