Python can you accidentally overwrite a logger by using getLogger with the same name?

半城伤御伤魂 提交于 2020-01-06 12:21:11

问题


In my Python program, I import a module (let's say it's called bananas). The module gets a logger inside its __init__.py by doing this: _logger = logging.getLogger(__name__). Thus, the logger's name is bananas.

In my program (the one that imports the module bananas), I also have this line: my_logger = logging.getLogger("bananas").

Does this:

  • Overwrite _logger made in bananas?
  • Fetch that logger, and thus my_logger now equals _logger?
  • Something else entirely

Thank you for your help!


回答1:


It fetches the bananas logger, so that my_logger is the same object as bananas._logger.



来源:https://stackoverflow.com/questions/56840220/python-can-you-accidentally-overwrite-a-logger-by-using-getlogger-with-the-same

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!