def test_get_exec_info(self): template = '{source} {line} {function} {process}: {message}' logger = Logger(name='exec-info', template=template) with CaptureOutput() as co: logger.info('hello') output = co.get_text() regex = '[\w/]+\.py \d+ \w+ \d+: [^\n]+' assert re.match(regex, output)
def test_additional_context_static(self): template = '{name} {person}: {message}' logger = Logger(name='ad-static', template=template, additional_context={'person': 'vince'}) with CaptureOutput() as co: logger.info('hello') output = co.get_text() assert output == 'ad-static vince: hello'
def test_additional_context_static(self): template = "{name} {person}: {message}" logger = Logger(name="ad-static", template=template, additional_context={"person": "vince"}) with CaptureOutput() as co: logger.info("hello") output = co.get_text() assert output == "ad-static vince: hello"
def test_additional_context_function(self): template = '{uuid} {message}' logger = Logger(name='ad-func', template=template, additional_context={'uuid': uuid4}) with CaptureOutput() as co: logger.info('hello') output = co.get_text() assert re.match( '[a-f0-9]{8}-[a-f0-9]{4}-4[a-f0-9]{3}-[89ab][a-f0-9]{3}-[a-f0-9]{12} hello', output)
def test_additional_context_function(self): template = "{uuid} {message}" logger = Logger(name="ad-func", template=template, additional_context={"uuid": uuid4}) with CaptureOutput() as co: logger.info("hello") output = co.get_text() assert re.match( "[a-f0-9]{8}-[a-f0-9]{4}-4[a-f0-9]{3}-[89ab][a-f0-9]{3}-[a-f0-9]{12} hello", output, )
def test_set_template(self): logger = Logger(name='template') assert logger.template == Logger.DEFAULT_TEMPLATE template = '{timestamp} {message}' keys = {'timestamp', 'message'} logger.template = template assert logger.template == template assert logger.keys == keys with CaptureOutput() as co: logger.info('Hello, world!') output = co.get_text() regex = f'{_timestamp_group} {_message_group}' assert re.match(regex, output)
def test_set_template(self): logger = Logger(name="template") assert logger.template == Logger.DEFAULT_TEMPLATE template = "{timestamp} {message}" keys = {"timestamp", "message"} logger.template = template assert logger.template == template assert logger.keys == keys with CaptureOutput() as co: logger.info("Hello, world!") output = co.get_text() regex = f"{_timestamp_group} {_message_group}" assert re.match(regex, output)