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):
51
51
settings .DRF_API_LOGGER_METHODS ) is list :
52
52
self .DRF_API_LOGGER_METHODS = settings .DRF_API_LOGGER_METHODS
53
53
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
+
54
60
def __call__ (self , request ):
55
61
56
62
# Run only if logger is enabled.
@@ -82,6 +88,10 @@ def __call__(self, request):
82
88
# the view (and later middleware) are called.
83
89
response = self .get_response (request )
84
90
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
+
85
95
# Code to be executed for each request/response after
86
96
# the view is called.
87
97
You can’t perform that action at this time.
0 commit comments