Skip to content

Do not use root logger#2076

Open
lachesis wants to merge 1 commit into
mindee:mainfrom
lachesis:patch-1
Open

Do not use root logger#2076
lachesis wants to merge 1 commit into
mindee:mainfrom
lachesis:patch-1

Conversation

@lachesis

Copy link
Copy Markdown
Contributor

Calling logging.info() at module level with no logger configured triggers logging.basicConfig() automatically (Python's "last resort" behavior) — which creates a StreamHandler on root with WARNING level.

This poisons logging config for anything downstream of this.

Instead, create a logger scoped to doctr package.

Example repro script:

#!/usr/bin/env python
from doctr.io import Document

import logging
logging.basicConfig(level=logging.INFO)

logging.info("I do not see this")
logging.warning("I still see this")

Output:

WARNING:root:I still see this

Expected:

INFO:root:I do not see this
WARNING:root:I still see this

Calling logging.info() at module level with no logger configured triggers logging.basicConfig() automatically (Python's "last resort" behavior) — which creates a StreamHandler on root with WARNING level.

This poisons logging config for anything downstream of this.

Instead, create a logger scoped to doctr package.
@lachesis

Copy link
Copy Markdown
Contributor Author

Oh I see this anti-pattern is pretty common in doctr. It should really be fixed in all of the affected files. Maybe I'll open a more comprehensive PR later.

@codecov

codecov Bot commented Jun 17, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 96.88%. Comparing base (b45b899) to head (6e26e86).

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2076      +/-   ##
==========================================
- Coverage   96.93%   96.88%   -0.06%     
==========================================
  Files         156      156              
  Lines        7415     7415              
==========================================
- Hits         7188     7184       -4     
- Misses        227      231       +4     
Flag Coverage Δ
unittests 96.88% <ø> (-0.06%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant