Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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
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 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()
def _wrapper(request):
correlation_id = cf_logging.FRAMEWORK.request_reader.get_correlation_id(request)
cf_logging.FRAMEWORK.context.set_correlation_id(correlation_id, request)
cf_logging.FRAMEWORK.context.set('request_started_at', datetime.utcnow(), request)
return wrapped(request)