Multiple log files using logging module

Sharan Basappa sharan.basappa at gmail.com
Sun Mar 24 13:13:07 EDT 2019


I have a test program that imports a design program.
Both the programs need to log messages.

I have tried the following:

1) Both the programs have the following lines:
for handler in logging.root.handlers[:]:
    logging.root.removeHandler(handler)
    
#Create and configure logger
filename = os.path.join(os.path.dirname(os.path.realpath(__file__)), '<>')
logging.basicConfig(filename=filename, filemode='w', format='%(asctime)s %(message)s')
#Creating an object
logger = logging.getLogger()
#Setting the threshold of logger to DEBUG
logger.setLevel(logging.DEBUG)

replace <> above with respective log file names for test and design programs.
However, the test program logs the messages but not the design program.

2) I removed the above lines from design program altogether hoping that the messages will appear in the same log file. There is no error, however, no message is logged from the design program.

I would like to get comment from members here as well as some simple programs to illustrate this ...



More information about the Python-list mailing list