Skip to content

logging.basicConfig(...) at import time reconfigures the root logger for the whole process #44

Description

@rwest

Summary
pysidt/sidt.py calls logging.basicConfig(level=logging.INFO) at module import time (line 28), and logs throughout via the root logger (logging.info(...), logging.warning(...), etc.). Both are discouraged for libraries: importing PySIDT silently reconfigures logging for any program that imports it (directly or transitively).

Why this is a problem
A library shouldn't configure the root logger — that's the application's responsibility. The Python "Logging HOWTO" → Configuring Logging for a Library recommends a library add at most a NullHandler and leave configuration to the app.

The current behavior has two side effects on consumers:

  1. basicConfig(level=logging.INFO) at import forces the root logger to INFO and attaches a stderr handler for the entire process. Any program that imports PySIDT (or imports something that imports it) inherits this.
  2. Logging through the root logger (rather than a module-level named logger) means PySIDT's messages aren't namespaced, so consumers can't selectively adjust PySIDT's verbosity without affecting their whole application.

How we hit it
We import PySIDT transitively in RMG-Py (via rmgpy.data.thermo). A tool that emitted INFO logs suddenly started writing them to stderr — purely because importing PySIDT had switched the root logger to INFO + stderr. We worked around it with logging.basicConfig(level=logging.WARNING, force=True), but the root cause is upstream.

Suggested fix
Standard library-logging hygiene:

# pysidt/sidt.py
import logging

logger = logging.getLogger(__name__)   # module-level named logger
# (remove the logging.basicConfig(level=logging.INFO) call)

AI use
Issue drafted with help from Claude

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions