日志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)[源代码]

日志适配器允许 typesubtype 关键词。

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" ,关键级别的未着色,警告级别的着色为 "red" .

log(level, msg, *args, **kwargs)[源代码]
info(msg, *args, **kwargs)
verbose(msg, *args, **kwargs)[源代码]
debug(msg, *args, **kwargs)

用指定的级别将消息记录到此记录器。基本上,参数与Python的日志模块相同。

此外,sphinx记录器支持以下关键字参数:

nonl

如果为真,则记录器不会在日志消息末尾折叠行。默认值为 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() .

sphinx.util.logging.prefixed_warnings()[源代码]

上下文管理器临时为所有警告日志记录添加前缀。

例如::

>>> with prefixed_warnings("prefix:"):
>>>     logger.warning('Warning message!')  # => prefix: Warning message!

Added in version 2.0.