Skip to content

Route library-internal warnings through logging (#15)#106

Merged
matthewhorridge merged 1 commit into
mainfrom
feat/logging-cleanup
May 13, 2026
Merged

Route library-internal warnings through logging (#15)#106
matthewhorridge merged 1 commit into
mainfrom
feat/logging-cleanup

Conversation

@matthewhorridge
Copy link
Copy Markdown
Contributor

Summary

Closes #15. Library-internal warnings now use the `logging` module instead of `print()`, so they no longer pollute stdout (which matters because the CLI streams harmonized CSV through stdout when piped) and can be filtered by severity.

Five call sites changed to `logger.warning(...)`:

  • `RuleSet.add_rule` — duplicate-target warning
  • `Bin.transform` — value outside any bin
  • `EnumToEnum.transform` — missing mapping in non-strict mode
  • `Reduce.onehot_reduction` — two error paths

Each module declares `logger = logging.getLogger(name)` at top level, so callers can configure or suppress these warnings per-module if they want.

Deliberately left as `print()`

  • `cli.py` — `Warning: skipping missing source columns: ...` (user-facing CLI output)
  • `harmonize.py` — `Applying rule -> target (sources: [...])` (user-facing progress output)

Those are direct CLI ergonomics, not library logging events.

Test plan

  • All 131 tests still pass
  • CLI behaviour unchanged — `test_cli_missing_behavior` still captures the warning message it expects

🤖 Generated with Claude Code

Five primitive/registry call sites used `print()` for warnings:
RuleSet.add_rule, Bin.transform, EnumToEnum.transform, and two paths
inside Reduce.onehot_reduction. These polluted stdout (which the CLI
also uses for harmonized CSV output when piped), couldn't be silenced,
and lacked any way to filter by severity. Replace with module-level
`logging.getLogger(__name__).warning(...)`.

The two user-facing `print()` calls in `cli.py` and `harmonize.py` are
left alone — those are intentional progress output for the CLI user
and belong on stdout.

Resolves #15.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@matthewhorridge matthewhorridge merged commit 3469df4 into main May 13, 2026
1 check passed
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.

Replace print statements with proper logging

1 participant