是否可以将structlog与pythonw一起使用以只登录文件?
当使用pythonw运行python代码时,导入structlog失败,因为sys.stdout是None。
当调用structlog/_config.py文件时,sys.stdout.isatty()会引发错误。
这里有一个简单的测试来揭示这个问题。
# python try_import_structlog.pyw --> success
# pythonw try_import_structlog.pyw --> fail
with open("result.txt", "a") as file:
try:
import structlog
except Exception as error:
file.write(f"import failed: {error}")
else:
file.write("import succeeded")发布于 2021-04-30 13:00:44
这是结构日志中的一个bug,将在下一个版本中修复!我想这个周末可能就出来了。
https://stackoverflow.com/questions/67315429
复制相似问题