日志记录API¶
- sphinx.util.logging.getLogger(name)[源代码]¶
将记录器包装为
sphinx.util.logging.SphinxLoggerAdapter
。Sphinx记录器总是使用
sphinx.*
命名空间独立于根记录器的设置。即使第三方扩展或导入的应用程序重置了记录器设置,它也能确保日志记录的一致性。示例用法::
>>> from sphinx.util import logging >>> logger = logging.getLogger(__name__) >>> logger.info('Hello, this is an extension!') Hello, this is an extension!
- class sphinx.util.logging.SphinxLoggerAdapter(logging.LoggerAdapter)[源代码]¶
LoggerAdapter允许
type
和subtype
关键字。- error(msg, *args, **kwargs)¶
- critical(msg, *args, **kwargs)¶
- warning(msg, *args, **kwargs)[源代码]¶
在此记录器上记录具有指定级别的消息。基本上,其参数与Python的日志记录模块相同。
此外,Sphinx记录器还支持以下关键字参数:
- type , *subtype *
警告日志的类别。它用于通过以下方式抑制警告
suppress_warnings
布景。- location
也就是发出警告的地方。它用于在每个日志中包含路径和行号。它允许Docname、Docname和行号的元组以及节点::
logger = sphinx.util.logging.getLogger(__name__) logger.warning('Warning happened!', location='index') logger.warning('Warning happened!', location=('chapter1/index', 10)) logger.warning('Warning happened!', location=some_node)
- color
原木的颜色。默认情况下,错误级别日志的颜色为
"darkred"
,严重级别1不着色,警告级别1着色为"red"
。
- info(msg, *args, **kwargs)¶
- debug(msg, *args, **kwargs)¶
将具有指定级别的消息记录到此记录器。基本上,其参数与Python的日志记录模块相同。
此外,Sphinx记录器还支持以下关键字参数:
- nonl
如果为True,则记录器不会在日志消息的末尾折叠线条。缺省值为
False
。- location
消息是在哪里发出的。有关更多详细信息,请参阅
SphinxLoggerAdapter.warning()
。- color
原木的颜色。默认情况下,信息和详细级别的日志不会着色,而调试级别的日志会着色为
"darkgray"
。
- sphinx.util.logging.pending_logging()[源代码]¶
上下文管理器临时推迟记录所有日志。
例如::
>>> with pending_logging(): >>> logger.warning('Warning message!') # not flushed yet >>> some_long_process() >>> Warning message! # the warning is flushed here
- sphinx.util.logging.pending_warnings()[源代码]¶
上下文管理器可暂时推迟日志记录警告。
类似于
pending_logging()
。