referring to this question here: LINK How can I set up a config, that will only log my root script and my own sub-scripts? The question of the link asked for disabling all imported modules, but that is not my intention.
My root setup:
import logging from exchangehandler import send_mail log_wp = logging.getLogger(__name__) logging.basicConfig(level=logging.DEBUG, format='%(asctime)s - %(levelname)s [%(filename)s]: %(name)s %(funcName)20s - Message: %(message)s', datefmt='%d.%m.%Y %H:%M:%S', filename='C:/log/myapp.log', filemode='a') handler = logging.StreamHandler() log_wp.addHandler(handler) log_wp.debug('This is from root') send_mail('[email protected]', 'Request', 'Hi there') My sub-module exchangehandler.py:
import logging log_wp = logging.getLogger(__name__) def send_mail(mail_to,mail_subject,mail_body, mail_attachment=None): log_wp.debug('Hey this is from exchangehandler.py!') m.send_and_save() myapp.log:
16.07.2018 10:27:40 - DEBUG [test_script.py]: __main__ <module> - Message: This is from root 16.07.2018 10:28:02 - DEBUG [exchangehandler.py]: exchangehandler send_mail - Message: Hey this is from exchangehandler.py! 16.07.2018 10:28:02 - DEBUG [folders.py]: exchangelib.folders get_default_folder - Message: Testing default <class 'exchangelib.folders.SentItems'> folder with GetFolder 16.07.2018 10:28:02 - DEBUG [services.py]: exchangelib.services get_payload - Message: Getting folder ArchiveDeletedItems (archivedeleteditems) 16.07.2018 10:28:02 - DEBUG [services.py]: exchangelib.services get_payload - Message: Getting folder ArchiveInbox (archiveinbox) My problem is, that the log-file contains also a lot of information of the exchangelib-module, that is imported in exchangehandler.py. Either the imported exchangelib-module is configured incorrectly or I have made a mistake. So how can I reduce the log-output only to my logging messages?
EDIT: An extract of the folder.py of the exchangelib-module. This is not anything that I have written:
import logging log = logging.getLogger(__name__) def get_default_folder(self, folder_cls): try: # Get the default folder log.debug('Testing default %s folder with GetFolder', folder_cls) # Use cached instance if available for f in self._folders_map.values(): if isinstance(f, folder_cls) and f.has_distinguished_name: return f return folder_cls.get_distinguished(account=self.account)