def _check_falcon_request_log(app, headers, expected):
    _, stream = config_logger('cf.falcon.logger')

    client = testing.TestClient(app)
    _check_expected_response(client.simulate_get('/test/path',
                                                 headers=headers))
    assert check_log_record(stream, WEB_LOG_SCHEMA, expected) == {}
def _check_django_request_log(headers, expected):
    _, stream = config_logger('cf.django.logger')

    client = Client()
    _check_expected_response(client.get('/test/path', **headers),
                             body='Hello test!')
    assert check_log_record(stream, WEB_LOG_SCHEMA, expected) == {}
Beispiel #3
0
def test_logging_without_request():
    """ Test logger is usable in non request context """
    app = Flask(__name__)
    _set_up_flask_logging(app)
    logger, stream = config_logger('main.logger')
    logger.info('works')
    assert check_log_record(stream, JOB_LOG_SCHEMA, {'msg': v_str('works')}) == {}
 async def _logging_correlation_id_route(request):
     logger, stream = config_logger('user.logging')
     new_extra = extend(extra,
                        {'request': request}) if provide_request else extra
     logger.info('in route headers', extra=new_extra)
     assert check_log_record(stream, JOB_LOG_SCHEMA, expected) == {}
     return text('ok')
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 == {}
def test_logging_without_request():
    """ Test logger is usable in non request context """
    app = falcon.API()
    _set_up_falcon_logging(app)
    cf_logging.FRAMEWORK.context.set_correlation_id('value')

    logger, stream = config_logger('main.logger')
    logger.info('works')
    assert check_log_record(stream, JOB_LOG_SCHEMA,
                            {'msg': v_str('works')}) == {}
def test_exception_stacktrace():
    """ Test exception stacktrace is logged """
    cf_logging.init(level=logging.DEBUG)
    logger, stream = config_logger('cli.test')

    try:
        return 1 / 0
    except ZeroDivisionError:
        logger.exception('zero division error')
        log_json = JSONDecoder().decode(stream.getvalue())
        _, error = JsonValidator(JOB_LOG_SCHEMA).validate(log_json)

        assert error == {}
        assert 'ZeroDivisionError' in str(log_json['stacktrace'])
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
Beispiel #9
0
def test_flask_request_log(headers, expected):
    """ That the expected records are logged by the logging library """

    app = Flask(__name__)

    @app.route('/test/path')
    def _root():
        return Response('ok', mimetype='text/plain')

    _set_up_flask_logging(app)
    _, stream = config_logger('cf.flask.logger')

    client = app.test_client()
    _check_expected_response(client.get('/test/path', headers=headers))
    assert check_log_record(stream, WEB_LOG_SCHEMA, expected) == {}
def test_sanic_request_log(headers, expected):
    """ Test that the JSON logs contain the expected properties based on the
        input.
    """
    app = sanic.Sanic('test cf_logging')

    @app.route('/test/path')
    async def _headers_route(request):
        if 'no-content-length' in request.headers:
            return text('ok', headers={'Content-Type': 'text/plain'})
        return text('ok',
                    headers={
                        'Content-Length': 2,
                        'Content-Type': 'text/plain'
                    })

    _set_up_sanic_logging(app)
    _, stream = config_logger('cf.sanic.logger')

    client = app.test_client
    _check_expected_response(
        client.get('/test/path', headers=headers)[1], 200, 'ok')
    assert check_log_record(stream, WEB_LOG_SCHEMA, expected) == {}
 def __init__(self, *args, **kwargs):
     self.logger, self.stream = config_logger('user.logging')
     super(UserLoggingView, self).__init__(*args, **kwargs)
 def __init__(self, extra, expected):
     self.extra = extra
     self.expected = expected
     self.logger, self.stream = config_logger('user.logging')
Beispiel #13
0
 def _logging_correlation_id_route():
     logger, stream = config_logger('user.logging')
     logger.info('in route headers', extra=extra)
     assert check_log_record(stream, JOB_LOG_SCHEMA, expected) == {}
     return Response('ok')