I was wondering how to implement a global logger that could be used everywhere with your own settings:
I currently have a custom logger class:
class customLogger(logging.Logger):
...
The class is in a separate file with some formatters and other stuff.
The logger works perfectly on its own.
I import this module in my main python file and create an object like this:
self.log = logModule.customLogger(arguments)
But obviously, I cannot access this object from other parts of my code.
Am i using a wrong approach? Is there a better way to do this?
Use
logging.getLogger(name)to create a named global logger.main.py
log.py
submodule.py
Output