Skip to content

Importing area_reader calls logging.basicConfig and INFO-logs every section #11

Description

@ctoth

https://github.com/ctoth/area_reader/blob/3297b88/area_reader/__init__.py#L3-L5

import logging
logger = logging.getLogger('area_reader')
logging.basicConfig(level=logging.INFO)

import area_reader configures the root logger of whatever application imports it — a library should never call basicConfig at import time. Combined with the per-section logger.info("Processing section %s" % section_name) in load_sections, any consumer gets stderr chatter for every section of every file it parses:

INFO:area_reader:Processing section area
INFO:area_reader:Processing section helps
INFO:area_reader:Processing section mobiles
...

and their own subsequent basicConfig call becomes a no-op because the root logger already has a handler.

Suggested fix, the standard library-logging pattern:

  • drop logging.basicConfig(...);
  • optionally logger.addHandler(logging.NullHandler());
  • demote the per-section "Processing section" lines to logger.debug (there are already debug calls for per-record progress; INFO-per-section is the same category of trace);
  • keep %-style lazy formatting (logger.info("Processing section %s", name)) instead of pre-formatted strings, matching the other call sites.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions