日志接口¶
- sphinx.util.logging.getLogger(name)[源代码]¶
获取记录器包装者:类:sphinx.util.logging.SphinxLoggerAdapter。
Sphinx logger始终使用“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 logger支持以下关键字参数:
- type, *subtype*
警告日志的类别。它用于通过以下方式抑制警告:confval:`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”,严重级别的日志不被着色,警告级别的日志被标记为“red”。
- info(msg, *args, **kwargs)¶
- sphinx.util.logging.pending_logging()[源代码]¶
Context manager to postpone logging all logs temporarily.
例如:
>>> with pending_logging(): >>> logger.warning('Warning message!') # not flushed yet >>> some_long_process() >>> Warning message! # the warning is flushed here