Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def on_get(self, req, resp):
self.extra.update({REQUEST_KEY: req})
self.logger.log(logging.INFO, 'in route headers', extra=self.extra)
assert check_log_record(self.stream, JOB_LOG_SCHEMA, self.expected) == {}
resp.set_header('Content-Type', 'text/plain')
resp.status = falcon.HTTP_200
resp.body = 'ok'
def get(self, request, *args, **kwargs):
""" Log a custom user message with the logger """
expected = kwargs.get('expected') or {}
extra = kwargs.get('extra') or {}
if self.provide_request:
extra.update({REQUEST_KEY: request})
self.logger.log(logging.INFO, 'in route headers', extra=extra)
assert check_log_record(self.stream, JOB_LOG_SCHEMA, expected) == {}
return HttpResponse("ok", content_type='text/plain')
def test_init_cf_logger_simple_log():
""" tests CfLogger creates SimpleLogRecord if extra is incomplete """
assert isinstance(_make_record(extra={}), SimpleLogRecord)
assert isinstance(_make_record(extra={REQUEST_KEY: {}}), SimpleLogRecord)
assert isinstance(_make_record(extra={RESPONSE_KEY: {}}), SimpleLogRecord)
def __init__(self, extra, framework, *args, **kwargs):
super(SimpleLogRecord, self).__init__(*args, **kwargs)
utcnow = datetime.utcnow()
self.written_at = util.iso_time_format(utcnow)
self.written_ts = util.epoch_nano_second(utcnow)
request = extra[REQUEST_KEY] if extra and REQUEST_KEY in extra else None
self.correlation_id = framework.context.get_correlation_id(request) or defaults.UNKNOWN
self.extra = dict((key, value) for key, value in extra.items()
if key not in _SKIP_ATTRIBUTES) if extra else {}
for key, value in self.extra.items():
setattr(self, key, value)
def __init__(self, extra, framework, *args, **kwargs):
super(RequestWebRecord, self).__init__(extra, framework, *args, **kwargs)
context = framework.context
request_reader = framework.request_reader
response_reader = framework.response_reader
request = extra[REQUEST_KEY]
response = extra[RESPONSE_KEY]
props = dict((key, value) for key, value in extra.items()
if key not in [RESPONSE_KEY, REQUEST_KEY])
for key, value in props.items():
setattr(self, key, value)
length = request_reader.get_content_length(request)
remote_ip = request_reader.get_remote_ip(request)
self.type = 'request'
self.direction = 'IN'
self.remote_user = request_reader.get_remote_user(request)
self.request = request_reader.get_path(request)
self.referer = request_reader.get_http_header(
request, 'referer', defaults.UNKNOWN)