Python:`logger.info`和`logging.info`有什么区别? [英] Python: What are differences between `logger.info` and `logging.info`?
本文介绍了Python:`logger.info`和`logging.info`有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想知道下面两个版本之间有什么区别?以及如何有效使用它?
I wonder what is the differences between two versions below? And how to use it effectively?
版本1:
import logging
logging.info("Hello world!")
版本2:
import logging
logger = logging.getLogger(__name__)
logger.info("Hello world!")
推荐答案
我运行我的代码:
class TestBedLog():
async def test(self):
import logging
logging.info("Log from logging")
logger = logging.getLogger(__name__)
logger.info("Log from logger")
结果是:
root: INFO: Log from logging
src.myserver.test.test_apiv2.test_bedlog: INFO: Log from logger
如您所见,日志记录
来自 root
.然后 logger
,您将看到用于记录信息的文件
As you can see, logging
is from the root
. And logger
you will see the file where log the information
这篇关于Python:`logger.info`和`logging.info`有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文