简体   繁体   English

logging.info和logging.getLogger()。info之间有什么区别?

[英]What is the difference between logging.info and logging.getLogger().info?

I am a fresh man of python. 我是蟒蛇的新人。

If logging.info() is enough for logging, why we have to instantiate a logger with getLogger() method? 如果logging.info()足以进行日志记录,为什么我们必须使用getLogger()方法实例化记录器?

Calling getLogger() without a name returns the root logger : 调用没有名称的getLogger() 返回根记录器

Return a logger with the specified name or, if no name is specified, return a logger which is the root logger of the hierarchy . 返回具有指定名称的记录器,或者, 如果未指定名称, 则返回记录器,该记录器是层次结构的根记录器

Calling the module-level info() function logs directly to the root logger : 调用模块级info()函数直接记录到根记录器

Logs a message with level INFO on the root logger . 在根记录器上记录级别为INFO的消息。

If you have no use for specifically named loggers (for example in order to identify the emitting module of the log), the two calls are exactly equivalent. 如果您没有使用专门命名的记录器(例如,为了识别日志的发射模块),这两个调用完全相同。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM