Python 根记录器在哪里存储日志?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4042615/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-18 13:59:08  来源:igfitidea点击:

Where does Python root logger store a log?

pythonloggingfreebase

提问by Matt Norris

I'm using the Freebase Python library. It creates a log before executing:

我正在使用 Freebase Python 库。它在执行之前创建一个日志:

self.log = logging.getLogger("freebase")

Where is this log in the file system?It's not in the executing directory or tmp.

此日志在文件系统中的什么位置?它不在执行目录或 tmp 中。

采纳答案by Jason R. Coombs

That call does not store anything. It merely creates a logger object which can be bound and configured however you would like.

该调用不存储任何内容。它只是创建一个记录器对象,可以根据需要对其进行绑定和配置。

So if in your Python code, you were to add

所以如果在你的 Python 代码中,你要添加

logging.basicConfig(level=logging.WARNING)

All warnings and errors would be logged to the standard output (that's what basicConfig does), including the calls that Freebase makes. If you want to log to the filesystem or other target, you'll want to reference the logging module documentationfor more information. You may also wish to reference the Logging HOWTO.

所有警告和错误都会被记录到标准输出(basicConfig 就是这样做的),包括 Freebase 发出的调用。如果要登录到文件系统或其他目标,则需要参考日志模块文档以获取更多信息。您可能还希望参考Logging HOWTO