Here is what I have in the main code:
from mf import gameplay
....
if __name__ == "__main__":
import logging
logger = logging.getLogger(__name__)
logger.setLevel(logging.INFO)
# create a file handler
handler = logging.FileHandler('example.log')
handler.setLevel(logging.INFO)
# create a logging format
formatter = logging.Formatter('%(asctime)s - %(worker)s - %(levelname)s - %(message)s')
handler.setFormatter(formatter)
# add the file handler to the logger
logger.addHandler(handler)
logger.info("Querying database for docs...", extra={'worker': 'id_1'})
and in a module gameplay
I import in the main code I have
import logging
logger = logging.getLogger("__main__")
logger.info("test module")
but still I do not get any log output from the logger in the module. I do not see the text "test module" in the logging file "example.log".
I looked HERE, HERE, HERE and HERE and I think I followed what is described in all these articles but it is still not working for me. I am pretty sure I overlooked something totally simple.
What am I missing?
MacOS, python 3.9.6