How to use the sap.cf_logging.init 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 / test_job_logging.py View on Github external
def test_log_in_expected_format(log_callback):
    """ Test the cf_logger as a standalone """
    cf_logging.init(level=logging.DEBUG)
    logger, stream = config_logger('cli.test')
    log_callback(logger, 'hi')
    log_json = JSONDecoder().decode(stream.getvalue())
    _, error = JsonValidator(JOB_LOG_SCHEMA).validate(log_json)

    assert error == {}
github SAP / cf-python-logging-support / tests / test_job_logging.py View on Github external
def test_thread_safety():
    """ test context keeps separate correlation ID per thread """
    class _SampleThread(threading.Thread):
        def __init__(self):
            super(_SampleThread, self).__init__()
            self.correlation_id = str(uuid.uuid1())
            self.read_correlation_id = ''

        def run(self):
            cf_logging.FRAMEWORK.context.set_correlation_id(self.correlation_id)
            time.sleep(0.1)
            self.read_correlation_id = cf_logging.FRAMEWORK.context.get_correlation_id()

    cf_logging.init(level=logging.DEBUG)

    thread_one = _SampleThread()
    thread_two = _SampleThread()

    thread_one.start()
    thread_two.start()

    thread_one.join()
    thread_two.join()

    assert thread_one.correlation_id == thread_one.read_correlation_id
    assert thread_two.correlation_id == thread_two.read_correlation_id
github SAP / cf-python-logging-support / tests / unit / test_init.py View on Github external
def test_init_called_twice(mocker):
    """ test cf_logging.init can be called only once """
    framework = mocker.Mock(Framework)
    cf_logging._SETUP_DONE = False
    cf_logging.init(framework, level=logging.DEBUG)
    cf_logging.init(framework, level=logging.DEBUG)
github SAP / cf-python-logging-support / tests / unit / test_init.py View on Github external
def test_init_incorrect_framework():
    """ test cf_logging.init fails for invalid framework """
    cf_logging._SETUP_DONE = False
    cf_logging.init({})
github SAP / cf-python-logging-support / tests / test_job_logging.py View on Github external
def test_set_correlation_id():
    """ Test setting correlation_id """
    correlation_id = '1234'
    cf_logging.init(level=logging.DEBUG)
    cf_logging.FRAMEWORK.context.set_correlation_id(correlation_id)

    logger, stream = config_logger('cli.test')
    logger.info('hi')

    log_json = JSONDecoder().decode(stream.getvalue())
    _, error = JsonValidator(JOB_LOG_SCHEMA).validate(log_json)

    assert error == {}
    assert log_json['correlation_id'] == correlation_id
    assert cf_logging.FRAMEWORK.context.get_correlation_id() == correlation_id
github SAP / cf-python-logging-support / sap / cf_logging / flask_logging / __init__.py View on Github external
def _init_framework(level):
    logging.getLogger('werkzeug').disabled = True

    framework = Framework(FLASK_FRAMEWORK_NAME,
                          FlaskContext(), FlaskRequestReader(), FlaskResponseReader())
    cf_logging.init(framework, level)
github SAP / cf-python-logging-support / sap / cf_logging / sanic_logging / __init__.py View on Github external
:param level: - valid log level from standard logging package (optional)
    :param custom_framework: - `Framework` instance - use in case you need
        to change request processing behaviour for example to customize context storage
    """
    if not isinstance(app, Sanic):
        raise TypeError('application should be instance of Sanic')

    framework = custom_framework or \
                Framework(
                    SANIC_FRAMEWORK_NAME,
                    SanicContext(),
                    SanicRequestReader(),
                    SanicResponseReader()
                )

    cf_logging.init(framework, level)

    @app.middleware('request')
    @before_request
    def _before_request(request):  # pylint: disable=unused-argument
        pass

    @app.middleware('response')
    @after_request
    def _after_request(request, response):  # pylint: disable=unused-argument
        pass