Skip to main content

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

LangSmith 包使用 Python 内置的logging输出日志的机制 了解其对 Standard Output 的行为。

确保已配置日志记录

注意

默认情况下,Jupyter 笔记本将日志发送到标准错误而不是标准输出,这意味着您的 除非您像下面那样配置日志记录,否则日志不会显示在您的 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)

增加记录器的详细程度

调试问题时,将日志增加到更高级别的详细程度会很有帮助,以便更多信息 outputd 到 standard output。Python 记录器默认使用WARNINGlog 级别,但您可以选择 不同的值来获得不同级别的详细程度。值(从最不详细到最详细)为ERROR,WARNING,INFODEBUG.您可以按如下方式进行设置:


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 上留下详细的反馈。