How to use the sap.cf_logging.core.constants.RESPONSE_KEY function in sap

To help you get started, we’ve selected a few sap examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github SAP / cf-python-logging-support / tests / unit / record / test_request_log_record.py View on Github external
def test_hiding_sensitive_fields_by_default():
    log_record = RequestWebRecord({REQUEST_KEY: None, RESPONSE_KEY: None},
                                  FRAMEWORK, 'name', logging.DEBUG, 'pathname', 1, 'msg', [], None)

    _assert_sensitive_fields_redacted(log_record)
    assert log_record.remote_user == defaults.REDACTED
    assert log_record.referer == defaults.REDACTED
github SAP / cf-python-logging-support / tests / unit / test_init.py View on Github external
def test_init_cf_logger_web_log(mocker):
    """ tests CfLogger creates SimpleLogRecord if extra contains request and response """
    mocker.patch.object(RequestWebRecord, '__init__', lambda *a, **kwa: None)
    record = _make_record(extra={REQUEST_KEY: {}, RESPONSE_KEY: {}})
    assert isinstance(record, RequestWebRecord)
github SAP / cf-python-logging-support / sap / cf_logging / __init__.py View on Github external
def makeRecord(self, name, level, fn, lno, msg, msgargs, exc_info,
                   func=None, extra=None, *args, **kwargs):
        """ Returns SimpleLogMessage or a RequestWebRecord depending on the extra variable """
        # check what record type this is
        cls = None
        if extra is not None and REQUEST_KEY in extra and RESPONSE_KEY in extra:
            cls = RequestWebRecord
        else:
            cls = SimpleLogRecord

        return cls(extra, FRAMEWORK, name, level, fn, lno, msg, msgargs, exc_info,
                   func, *args, **kwargs)
github SAP / cf-python-logging-support / sap / cf_logging / flask_logging / __init__.py View on Github external
def _wrapper(response):
        cf_logging.FRAMEWORK.context.set(
            'response_sent_at', datetime.utcnow(), request)
        extra = {REQUEST_KEY: request, RESPONSE_KEY: response}
        logging.getLogger('cf.flask.logger').info('', extra=extra)
        return wrapped(response)
    return _wrapper
github SAP / cf-python-logging-support / sap / cf_logging / sanic_logging / __init__.py View on Github external
def _wrapper(request, response):
        cf_logging.FRAMEWORK.context.set('response_sent_at', datetime.utcnow(), request)
        extra = {REQUEST_KEY: request, RESPONSE_KEY: response}
        logging.getLogger('cf.sanic.logger').info('', extra=extra)
        return wrapped(request, response)
github SAP / cf-python-logging-support / sap / cf_logging / falcon_logging / __init__.py View on Github external
def process_response(self, request, response, resource, req_succeeded): # pylint: disable=unused-argument
        """Post-processing of the response (after routing).

        :param request: - Falcon Request object
        :param response: - Falcon Response object
        :param resource: - Falcon Resource object to which the request was routed
        :param req_succeeded: - True if no exceptions were raised while
            the framework processed and routed the request
        """
        cf_logging.FRAMEWORK.context.set(
            'response_sent_at', datetime.utcnow(), request)
        extra = {REQUEST_KEY: request, RESPONSE_KEY: response}
        logging.getLogger(self._logger_name).info('', extra=extra)
github SAP / cf-python-logging-support / sap / cf_logging / record / request_log_record.py View on Github external
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)
        self.x_forwarded_for = request_reader.get_http_header(
            request, 'x-forwarded-for', defaults.UNKNOWN)
        self.protocol = request_reader.get_protocol(request)
        self.method = request_reader.get_method(request)
github SAP / cf-python-logging-support / sap / cf_logging / record / simple_log_record.py View on Github external
import logging
import traceback

from datetime import datetime
from sap.cf_logging import defaults
from sap.cf_logging.core.constants import REQUEST_KEY, RESPONSE_KEY
from sap.cf_logging.record import application_info
from sap.cf_logging.record import util

from sap.cf_logging.formatters.stacktrace_formatter import format_stacktrace

_SKIP_ATTRIBUTES = ["type", "written_at", "written_ts", "correlation_id", "remote_user", "referer",
                    "x_forwarded_for", "protocol", "method", "remote_ip", "request_size_b",
                    "remote_host", "remote_port", "request_received_at", "direction",
                    "response_time_ms", "response_status", "response_size_b",
                    "response_content_type", "response_sent_at", REQUEST_KEY, RESPONSE_KEY]


class SimpleLogRecord(logging.LogRecord):
    """ SimpleLogRecord class holds data for user logged messages """

    # pylint: disable=too-many-arguments,too-many-locals

    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