sphinx_compatibility.py 文件源码

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

项目:bolero 作者: rock-learning 项目源码 文件源码
def _app_get_logger(name):
    class SphinxLoggerAdapter:
        def _color_to_func(self, kwargs, default=''):
            return getattr(sphinx.util.console,
                           kwargs.pop('color', default),
                           None)

        def error(self, msg, *args, **kwargs):
            msg = msg % args
            colorfunc = self._color_to_func(kwargs, default='red')
            return _app.warn(colorfunc(msg), **kwargs)

        def critical(self, msg, *args, **kwargs):
            msg = msg % args
            colorfunc = self._color_to_func(kwargs, default='red')
            return _app.warn(colorfunc(msg), **kwargs)

        def warning(self, msg, *args, **kwargs):
            msg = msg % args
            colorfunc = self._color_to_func(kwargs)
            if colorfunc:
                # colorfunc is a valid kwarg in 1.5, but not older, so we just
                # apply it ourselves.
                msg = colorfunc(msg)
            return _app.warn(msg, **kwargs)

        def info(self, msg='', *args, **kwargs):
            msg = msg % args
            colorfunc = self._color_to_func(kwargs)
            if colorfunc:
                msg = colorfunc(msg)
            return _app.info(msg, **kwargs)

        def verbose(self, msg, *args, **kwargs):
            return _app.verbose(msg, *args, **kwargs)

        def debug(self, msg, *args, **kwargs):
            return _app.debug(msg, *args, **kwargs)

    return SphinxLoggerAdapter()
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号