I have 3 python modules.
LogManager.py Runner.py Other.py
Runner.py
is the first core module in the event chain, and from this module, a function is called inside Other.py
.
So, inside Runner.py
, I have a call to the LogManager.py
function
logger = LogManager.get_log()
and from there I can make simple magazines, for example. logger.critical("OHNOES")
What I want to use get_log
something similar to a singleton template, where if the log has not been configured, it will configure the logger and return it. In addition, it will simply return the registrar.
The contents of LogManager.py:
import logging def get_log(): logger = logging.getLogger('PyPro') logger.setLevel(logging.DEBUG)
As you can see, LogManager.get_log () will try to configure the log every time it is called. Actually, I'm a little confused as to what is happening ...
Runner.py calls the get_log function in this main method. Other.py calls get_log in the global area (immediately after import, and not in any function)
As a result, all the logs I make are written twice, since the handlers are executed twice for the logger.
What is the easiest way that I'm missing to get get_log to return an instance of the same log?