I have two files: script.py and functions.py. In functions.py, I have logger setup, and a set of functions (made up one below):
class ecosystem(): def __init__(self, environment, mode): self.logger = logging.getLogger(__name__) if os.path.exists('log.log'): os.remove('log.log') handler= logging.FileHandler('log.log') if mode.lower()== 'info': handler.setLevel(logging.INFO) self.logger.setLevel(logging.INFO) elif mode.lower()== 'warning': handler.setLevel(logging.WARNING) self.logger.setLevel(logging.WARNING) elif mode.lower()== 'error': handler.setLevel(logging.ERROR) self.logger.setLevel(logging.ERROR) elif mode.lower()== 'critical': handler.setLevel(logging.CRITICAL) self.logger.setLevel(logging.CRITICAL) else: handler.setLevel(logging.DEBUG) self.logger.setLevel(logging.DEBUG) #Logging file format formatter = logging.Formatter(' %(levelname)s | %(asctime)s | %(message)s \n') handler.setFormatter(formatter) #Add the handler to the logger self.logger.addHandler(handler) self.logger.info('Logging starts here') def my_function(): self.logger.debug('test log')) return True I'm trying to call ecosystem.my_function from script.py, but when I do, the logger.debug message shows up in both the terminal window AND log.log. Any ideas why this might be happening?
If it helps, I also import other modules into functions.py, if those modules import logging as well, could that cause issues?