taolib.symphony.observability.logging#

结构化日志配置。

基于 structlog,支持 JSON 和 key=value 两种输出格式。 所有问题相关日志自动携带 issue_id、issue_identifier 上下文。

Functions#

configure_logging(→ None)

配置 structlog。

bind_issue_context(→ None)

绑定 issue 上下文到当前协程。

clear_issue_context(→ None)

清除 issue 上下文。

get_logger(→ structlog.stdlib.BoundLogger)

获取绑定名称的结构化日志器。

Module Contents#

taolib.symphony.observability.logging.configure_logging(level: str = 'info', format: str = 'json', output: str = 'stderr') None#

配置 structlog。

参数:
  • level -- 日志级别,如 "debug"、"info"、"warning"、"error"。

  • format -- 输出格式,"json" 或 "console"。

  • output -- 输出目标,"stderr" 或 "stdout"。

taolib.symphony.observability.logging.bind_issue_context(issue_id: str, identifier: str) None#

绑定 issue 上下文到当前协程。

之后的日志调用会自动携带 issue_id 和 issue_identifier 字段。

参数:
  • issue_id -- 问题内部 ID。

  • identifier -- 人类可读的问题标识(如 "PROJ-123")。

taolib.symphony.observability.logging.clear_issue_context() None#

清除 issue 上下文。

taolib.symphony.observability.logging.get_logger(name: str | None = None) structlog.stdlib.BoundLogger#

获取绑定名称的结构化日志器。

参数:

name -- 日志器名称,通常为模块名。

返回:

配置好的 structlog BoundLogger 实例。