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)
Exemple #2
0
    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)