我是python新手
如果 logging.info()
足以进行日志记录,为什么我们必须使用 getLogger()
方法实例化一个记录器?
最佳答案
在没有名称的情况下调用 getLogger()
returns the root logger :
Return a logger with the specified name or, if no name is specified, return a logger which is the root logger of the hierarchy.
调用模块级info()
函数logs directly to the root logger :
Logs a message with level INFO on the root logger.
如果您不需要专门命名的记录器(例如,为了识别日志的发出模块),这两个调用是完全等价的。
关于python - logging.info 和 logging.getLogger().info 有什么区别?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11225846/