Skip to content

[Feature] Update Logging#81

Merged
dfop02 merged 3 commits into
release/1.1.6from
feature/logging-updates
Jun 24, 2026
Merged

[Feature] Update Logging#81
dfop02 merged 3 commits into
release/1.1.6from
feature/logging-updates

Conversation

@dfop02

@dfop02 dfop02 commented Jun 20, 2026

Copy link
Copy Markdown
Owner

Description

Problem

All warnings were emitted via the root logger (logging.warning(...)), making it impossible for consumers to silence or configure html4docx output without affecting their entire application logging.

Changes

Logging overhaul

  • Added logger = logging.getLogger(__name__) to h4d.py, utils.py, and metadata.py
  • A single NullHandler on the package root (__init__.py) keeps the library silent by default — no handler needed per-module
  • Replaced all logging.<level>(...) and print(...) warning calls with logger.<level>(...) across all three modules
  • Downgraded "Unrecognized CSS style" messages from WARNINGDEBUG (expected skips for any real-world HTML, not actionable problems)

Tests

  • Updated test_custom_style_not_found_warning to assert against the named logger html4docx.h4d
  • Migrated test_metadata.py warning tests from capsys (stdout) → caplog (named logger)
  • Added tests verifying logger names, NullHandler placement, and that warnings are silenceable per-logger

Docs

  • Added a Logging section to README.md with recipes for silencing output in plain Python, Django LOGGING dict, and enabling debug-level detail

Linter

  • Fixed all 14 outstanding ruff offenses (SIM118, SIM401, SIM102, SIM201, SIM108, UP031, B905, B011)

Result

Consumers can now silence all html4docx output with a single config entry:

# Django LOGGING dict
"html4docx": {"level": "ERROR", "propagate": False}

# or plain Python
logging.getLogger("html4docx").setLevel(logging.ERROR)

Issue Reference

Fixes #80

Checklist Before Requesting a Review

  • I have performed a self-review of my code.
  • My code follows the project's coding style and guidelines.
  • I have run tests and verified that all existing and new tests pass.
  • I have added new tests to cover my changes.

@dfop02 dfop02 self-assigned this Jun 20, 2026
@dfop02 dfop02 added documentation Improvements or additions to documentation New Feature New feature or request labels Jun 20, 2026
@dfop02 dfop02 merged commit 8ce7f97 into release/1.1.6 Jun 24, 2026
6 checks passed
@dfop02 dfop02 deleted the feature/logging-updates branch June 24, 2026 12:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation New Feature New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Library logs through the root logger — use a module-level named logger instead

1 participant