Skip to main content

如何打印详细日志(Python SDK)

LangSmith 包使用 Python 的内置 logging 机制,将关于其行为日志输出到标准输出。

确保已配置日志记录

注意

默认情况下,Jupyter notebook 会将日志发送到标准错误而非标准输出,这意味着除非您按照我们以下所示的方式配置日志记录,否则您的日志将不会显示在 notebook 单元格输出中。

如果您的 Python 环境当前未配置将日志发送到标准输出,则需要按以下方式显式开启它:


import logging
# Note: this will affect _all_ packages that use python's built-in logging mechanism,
# so may increase your log volume. Pick the right log level for your use case.
logging.basicConfig(level=logging.WARNING)

提高日志的详细程度

在调试问题时,将日志级别提高到更详细的级别很有帮助,这样可以将更多信息输出到标准输出。Python 日志记录器默认使用 WARNING 日志级别,但您可以选择不同的值以获得不同详细程度的日志。这些值从最不详细到最详细依次为 ERRORWARNINGINFODEBUG。您可以按如下方式设置:


import langsmith
import logging

# Loggers are hierarchical, so setting the log level on "langsmith" will
# set it on all modules inside the "langsmith" package
langsmith_logger = logging.getLogger("langsmith")
langsmith_logger.setLevel(level=logging.DEBUG)

此页面有帮助吗?


您可以留下详细的反馈 在 GitHub 上