Skip to content

Commit 78d5bb0

Browse files
committed
fix: CLI stderr handler keyed on ownership, not presence
Greptile P2 on PR #252: the any-handler early return meant a foreign handler attached to the semble logger by an embedding application would suppress the CLI stderr handler, redirecting or discarding oversized-file warnings. Idempotence now keys on the CLI-owned handler type (_CliLogHandler), so repeated setup still adds exactly one handler while a preconfigured foreign logger no longer blocks stderr visibility. Lore-id: f488e6e1 Constraint: CLI logging setup must be idempotent across repeated in-process invocations Tested: 328 tests pass; ruff, ruff format, mypy clean Tested: in-process check: with a foreign NullHandler attached, CLI handler installed exactly once across two setup calls Related: c9380176 Confidence: high Scope-risk: narrow Reversibility: clean
1 parent 85d9140 commit 78d5bb0

1 file changed

Lines changed: 6 additions & 2 deletions

File tree

src/semble/cli.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -208,12 +208,16 @@ def _run_clear(clear_type: _CLEAR_CHOICE) -> None:
208208
_clear_orphans(cache_folder)
209209

210210

211+
class _CliLogHandler(logging.StreamHandler):
212+
"""stderr handler owned by the CLI; setup is idempotent on this type, not on foreign handlers."""
213+
214+
211215
def _configure_cli_logging() -> None:
212216
"""Surface semble warnings (e.g. skipped oversized files) on stderr without touching the root logger."""
213217
package_logger = logging.getLogger("semble")
214-
if package_logger.handlers:
218+
if any(isinstance(handler, _CliLogHandler) for handler in package_logger.handlers):
215219
return
216-
handler = logging.StreamHandler(sys.stderr)
220+
handler = _CliLogHandler(sys.stderr)
217221
handler.setFormatter(logging.Formatter("%(levelname)s: %(message)s"))
218222
package_logger.addHandler(handler)
219223
if package_logger.level == logging.NOTSET:

0 commit comments

Comments
 (0)