MCPcopy
hub / github.com/django/django / log_response

Function log_response

django/utils/log.py:291–323  ·  view source on GitHub ↗

Log errors based on HttpResponse status. Log 5xx responses as errors and 4xx responses as warnings (unless a level is given as a keyword argument). The HttpResponse status_code and the request are passed to the logger's extra parameter.

(
    message,
    *args,
    response=None,
    request=None,
    logger=request_logger,
    level=None,
    exception=None,
)

Source from the content-addressed store, hash-verified

289
290
291def log_response(
292 message,
293 *args,
294 response=None,
295 request=None,
296 logger=request_logger,
297 level=None,
298 exception=None,
299):
300 """
301 Log errors based on HttpResponse status.
302
303 Log 5xx responses as errors and 4xx responses as warnings (unless a level
304 is given as a keyword argument). The HttpResponse status_code and the
305 request are passed to the logger's extra parameter.
306 """
307 # Check if the response has already been logged. Multiple requests to log
308 # the same response can be received in some cases, e.g., when the
309 # response is the result of an exception and is logged when the exception
310 # is caught, to record the exception.
311 if getattr(response, "_has_been_logged", False):
312 return
313
314 log_message(
315 logger,
316 message,
317 *args,
318 level=level,
319 status_code=response.status_code,
320 request=request,
321 exception=exception,
322 )
323 response._has_been_logged = True

Callers 15

_precondition_failedFunction · 0.90
_rejectMethod · 0.90
get_responseMethod · 0.90
response_for_exceptionFunction · 0.90
getMethod · 0.90
innerFunction · 0.90
test_logs_2xx_as_infoMethod · 0.90

Calls 1

log_messageFunction · 0.85

Used in the wild real call sites across dependent graphs

searching dependent graphs…