From 2eb91ed67df7682690077e7ecc0c0de6fba3cbd0 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Mon, 29 Dec 2025 19:50:26 +0000 Subject: [PATCH] Address code review feedback on logging configuration - Use exact type check (type(h) is logging.StreamHandler) instead of isinstance to avoid confusion with FileHandler subclass - Catch specific exceptions (IOError, OSError, PermissionError) instead of bare Exception when creating FileHandler - Kept logging.ERROR as default to maintain consistency with existing behavior Co-authored-by: seanthegeek <44679+seanthegeek@users.noreply.github.com> --- parsedmarc/cli.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/parsedmarc/cli.py b/parsedmarc/cli.py index 627a75d..a6968dd 100644 --- a/parsedmarc/cli.py +++ b/parsedmarc/cli.py @@ -84,8 +84,9 @@ def _configure_logging(log_level, log_file=None): # Add StreamHandler with formatter if not already present # Check if we already have a StreamHandler to avoid duplicates + # Use exact type check to distinguish from FileHandler subclass has_stream_handler = any( - isinstance(h, logging.StreamHandler) and not isinstance(h, logging.FileHandler) + type(h) is logging.StreamHandler for h in logger.handlers ) @@ -107,7 +108,7 @@ def _configure_logging(log_level, log_file=None): ) fh.setFormatter(formatter) logger.addHandler(fh) - except Exception as error: + except (IOError, OSError, PermissionError) as error: logger.warning("Unable to write to log file: {}".format(error))