def log_response(self, response): """ Helper method provided to enable the logging of responses in case if the :attr:`HttpProtocol.access_log` is enabled. :param response: Response generated for the current request :type response: :class:`sanic.response.HTTPResponse` or :class:`sanic.response.StreamingHTTPResponse` :return: None """ if self.access_log: extra = {"status": getattr(response, "status", 0)} if isinstance(response, HTTPResponse): extra["byte"] = len(response.body) else: extra["byte"] = -1 extra["host"] = "UNKNOWN" if self.request is not None: if self.request.ip: extra["host"] = "{0}:{1}".format( self.request.ip, self.request.port ) extra["request"] = "{0} {1}".format( self.request.method, self.request.url ) else: extra["request"] = "nil" access_logger.info("", extra=extra)
def log_response(self, response): """ Helper method provided to enable the logging of responses in case if the :attr:`HttpProtocol.access_log` is enabled. :param response: Response generated for the current request :type response: :class:`sanic.response.HTTPResponse` or :class:`sanic.response.StreamingHTTPResponse` :return: None """ if self.access_log: extra = {"status": getattr(response, "status", 0)} if isinstance(response, HTTPResponse): extra["byte"] = len(response.body) else: extra["byte"] = -1 extra["host"] = "UNKNOWN" if self.request is not None: if self.request.ip: extra["host"] = "{0}:{1}".format(self.request.ip, self.request.port) extra["request"] = "{0} {1}".format(self.request.method, self.request.url) else: extra["request"] = "nil" access_logger.info("", extra=extra)
def log_response(self, response): if self.access_log: extra = { 'status': getattr(response, 'status', 0), } if isinstance(response, HTTPResponse): extra['byte'] = len(response.body) else: extra['byte'] = -1 extra['host'] = 'UNKNOWN' if self.request is not None: if self.request.ip: extra['host'] = '{0[0]}:{0[1]}'.format(self.request.ip) req_base = '{0} {1}'.format(self.request.method, self.request.url) req_from = self.request.remote_addr if self.request.remote_addr else "client" extra['request'] = f"{req_from} --->> {req_base}" else: extra['request'] = 'nil' access_logger.info('', extra=extra) if self.request.app.config.LOG_REQUEST_DETAILS: print(self.request.headers) if self.request.method == "POST": from pprint import pprint pprint(self.request.json) print(self.request.body) logger.info("------")
def log_response(self, response): if self.access_log: extra = { 'status': getattr(response, 'status', 0), } if isinstance(response, HTTPResponse): extra['byte'] = len(response.body) else: extra['byte'] = -1 extra['host'] = 'UNKNOWN' if self.request is not None: if isinstance(self.request, Request): # Add request ID to logs extra["context"] = self.request.request_id if self.request.ip: extra['host'] = '{0}:{1}'.format(self.request.ip, self.request.port) extra['method'] = self.request.method extra['path'] = self.request.path if self.request.query_string is not None and len(self.request.query_string) > 0: extra['query'] = self.request.query_string else: extra['request'] = 'nil' access_logger.info('received request', extra=extra)
def log_response(self) -> None: """ Helper method provided to enable the logging of responses in case if the :attr:`HttpProtocol.access_log` is enabled. """ req, res = self.request, self.response extra = { "status": getattr(res, "status", 0), "byte": getattr(self, "response_bytes_left", -1), "host": "UNKNOWN", "request": "nil", } if req is not None: if req.ip: extra["host"] = f"{req.ip}:{req.port}" extra["request"] = f"{req.method} {req.url}" access_logger.info("", extra=extra)
def log_response(self, response): if self.access_log: extra = { 'status': getattr(response, 'status', 0), } if isinstance(response, HTTPResponse): extra['byte'] = len(response.body) else: extra['byte'] = -1 if self.request: extra['host'] = '{0}:{1}'.format(self.request.ip[0], self.request.ip[1]) extra['request'] = '{0} {1}'.format(self.request.method, self.request.url) else: extra['host'] = 'UNKNOWN' extra['request'] = 'nil' access_logger.info('', extra=extra)
def log_response(self, response): if self.access_log: extra = {"status": getattr(response, "status", 0)} if isinstance(response, HTTPResponse): extra["byte"] = len(response.body) else: extra["byte"] = -1 extra["host"] = "UNKNOWN" if self.request is not None: if self.request.ip: extra["host"] = "{0}:{1}".format(self.request.ip, self.request.port) extra["request"] = "{0} {1}".format(self.request.method, self.request.url) else: extra["request"] = "nil" access_logger.info("", extra=extra)
def log_response(self, response): if self.access_log: extra = { 'status': getattr(response, 'status', 0), } if isinstance(response, HTTPResponse): extra['byte'] = len(response.body) else: extra['byte'] = -1 extra['host'] = 'UNKNOWN' if self.request is not None: if self.request.ip: extra['host'] = '{0[0]}:{0[1]}'.format(self.request.ip) extra['request'] = '{0} {1}'.format(self.request.method, self.request.url) else: extra['request'] = 'nil' access_logger.info('', extra=extra)
def log_response(self): """ Helper method provided to enable the logging of responses in case if the :attr:`HttpProtocol.access_log` is enabled. :param response: Response generated for the current request :type response: :class:`sanic.response.HTTPResponse` or :class:`sanic.response.StreamingHTTPResponse` :return: None """ req, res = self.request, self.response extra = { "status": getattr(res, "status", 0), "byte": getattr(self, "response_bytes_left", -1), "host": "UNKNOWN", "request": "nil", } if req is not None: if req.ip: extra["host"] = f"{req.ip}:{req.port}" extra["request"] = f"{req.method} {req.url}" access_logger.info("", extra=extra)