Intrastellar Explorer
Intrastellar Explorer

Reputation: 2471

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

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:

Thank you for your help!

Upvotes: 0

Views: 112

Answers (1)

Vinay Sajip
Vinay Sajip

Reputation: 99475

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

Upvotes: 1

Related Questions