From a0f1cd1b046cb76aef052246db5f4ce750c00f86 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Reinhard=20M=C3=BCller?= Date: Tue, 2 Mar 2021 17:43:03 +0100 Subject: [PATCH] Improve logging options Issue our own log messages independently of the "debug" parameter, so a user can activate our log messages through Python's standard logger config features, while still having dsabled smtplib's debug messages, which are very verbose and always go to stderr. Change the log output for failed and ambiguous verifications from "warning" to "info" as this is a normal function of the library and not something that would require attention. Also this makes sure that no log output is generated if logging is not configured at all (default is to only display warning and above). --- validate_email/mx_check.py | 3 +-- validate_email/validate_email.py | 8 ++------ 2 files changed, 3 insertions(+), 8 deletions(-) diff --git a/validate_email/mx_check.py b/validate_email/mx_check.py index 3c8fac1..fb98d9f 100644 --- a/validate_email/mx_check.py +++ b/validate_email/mx_check.py @@ -212,8 +212,7 @@ class _SMTPChecker(SMTP): return `True`, else raise exceptions described in `mx_check`. """ for host in hosts: - if self.debuglevel > 0: - LOGGER.debug(msg=f'Trying {host} ...') + LOGGER.debug(msg=f'Trying {host} ...') if self._check_one(host=host): return True # Raise appropriate exceptions when necessary diff --git a/validate_email/validate_email.py b/validate_email/validate_email.py index a3bf6d1..6d36560 100644 --- a/validate_email/validate_email.py +++ b/validate_email/validate_email.py @@ -63,12 +63,8 @@ def validate_email(email_address: str, *args, **kwargs): try: return validate_email_or_fail(email_address, *args, **kwargs) except SMTPTemporaryError as error: - message = f'Validation for {email_address!r} ambigious: {error}' - if kwargs.get('debug'): - LOGGER.warning(msg=message) + LOGGER.info(msg=f'Validation for {email_address!r} ambigious: {error}') return except EmailValidationError as error: - message = f'Validation for {email_address!r} failed: {error}' - if kwargs.get('debug'): - LOGGER.warning(msg=message) + LOGGER.info(msg=f'Validation for {email_address!r} failed: {error}') return False