如何打印详细日志 (Python SDK)
LangSmith 包使用 Python 内置的 logging
机制将其行为日志输出到标准输出。
确保日志已配置
注意
默认情况下,Jupyter notebook 将日志发送到标准错误而不是标准输出,这意味着除非您按照我们在下面配置的方式配置日志,否则日志不会显示在您的 notebook 单元格输出中。
如果您的 Python 环境当前未配置日志以发送到标准输出,您需要明确地将其打开,如下所示:
- 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
日志级别,但您可以选择不同的值以获得不同程度的详细程度。这些值从最不详细到最详细依次是 ERROR
、WARNING
、INFO
和 DEBUG
。您可以按如下方式设置:
- Python
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)