Python can you accidentally overwrite a logger by

2019-08-21 17:51发布

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条回答
仙女界的扛把子
2楼-- · 2019-08-21 17:59

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

查看更多
登录 后发表回答