One way to achieve this is to use a single logging library to log information from both run files. This can be done by creating a logger instance in each run file using the same configuration, such as the same log file or logging level. Then, use the same name for both logger instances, which will cause them to refer to the same logger object.
For example, in both run files:
import logging
# create logger
logger = logging.getLogger('my_logger')
logger.setLevel(logging.DEBUG)
# create file handler
fh = logging.FileHandler('my_log_file.log')
fh.setLevel(logging.DEBUG)
# create formatter
formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
fh.setFormatter(formatter)
# add handler to logger
logger.addHandler(fh)
# log information
logger.debug('Hello, world!')
By using the same logger name ('mylogger') in both run files, the logger objects will refer to the same logger, and all log messages from both run files will be stored in the same file ('mylog_file.log').
Asked: 2022-12-28 11:00:00 +0000
Seen: 7 times
Last updated: Nov 27 '22