The python logging module once imported and instantiated will be so across the process, inside all modules and threads. How did they achieve that effect?
Example:
myapp.py
import logging
import mylib
def main():
logging.basicConfig(filename='myapp.log', level=logging.INFO)
logging.info('Started')
mylib.do_something()
logging.info('Finished')
if __name__ == '__main__':
main()
mylib.py
import logging
def do_something():
logging.info('Doing something')
myapp.log
INFO:root:Started
INFO:root:Doing something
INFO:root:Finished
When a module is imported for the first time, the loaded module object is put into
sys.modules
. Later imports will then find the module object and not reload the module.The logging module has a bunch of module attributes which hold the state of logging configuration after the first import.