mirror of
https://github.com/domainaware/parsedmarc.git
synced 2026-02-17 07:03:58 +00:00
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>
This commit is contained in:
@@ -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))
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user