In a multi-module Python environment, the docs recommend that one run the following snippet in the first point of entry into the Python project to define project-wide logging.
# ABC.py
import logging
logging.basicConfig(filename='master.log', level=logging.INFO)
logging.info('Start Logging.')
If some other file is another potential first point of entry into the project, do I add the same snippet to the top of that file as well? What I am trying to achieve is to specify logging in a single central location regardless of which file is the first point of entry.
You could create a dedicated python script file just for setting up the logging. Basically, that file would contain exactly what your ABC.py
file contains now.
Then just import this file in every script that's a potential "entry point". Even if the file is imported twice, the code in the file will be run exactly once.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With