test_log.py 文件源码

python
阅读 28 收藏 0 点赞 0 评论 0

项目:takumi 作者: elemepi 项目源码 文件源码
def test_log_adapter():
    import logging
    from takumi.log import MetaAdapter
    import sys
    ctx = {}
    logging.basicConfig(level=logging.DEBUG, stream=sys.stdout)
    logger = MetaAdapter(logging.getLogger('takumi'), {'ctx': ctx})
    logger_class = logging.getLoggerClass()
    with mock.patch.object(logger_class, '_log') as mock_log:
        logger.info('hello world')
    mock_log.assert_called_with(20, '[-/- -] hello world', ())

    ctx['meta'] = {
        'client_name': 'test_client',
        'client_version': '1.0.1'
    }
    ctx['env'] = {'client_addr': '127.0.0.1'}
    with mock.patch.object(logger_class, '_log') as mock_log:
        logger.info('hello world')
    mock_log.assert_called_with(
        20, '[test_client/1.0.1 127.0.0.1] hello world', ())

    ctx['log_extra'] = '353456436546 xxxx yyyy'
    with mock.patch.object(logger_class, '_log') as mock_log:
        logger.info('hello world')
    mock_log.assert_called_with(
        20, '[test_client/1.0.1 127.0.0.1 353456436546 xxxx yyyy] hello world',
        ())
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号