Skip to content

fix(cli): install log sinks at startup so internals stay off the terminal - #169

Merged
Zongwei9888 merged 1 commit into
mainfrom
fix/cli-logging-setup
Aug 7, 2026
Merged

fix(cli): install log sinks at startup so internals stay off the terminal#169
Zongwei9888 merged 1 commit into
mainfrom
fix/cli-logging-setup

Conversation

@Zongwei9888

Copy link
Copy Markdown
Collaborator

Fixes #167.

Confirmed as reported

All three claims check out:

  • setup_logging() is never called. Every occurrence in the tree is a definition, a re-export or a docstring. Inspecting the handler table after importing the CLI shows loguru's own default still in place: one sink, id 0, level 10 (DEBUG), a StreamSink on stderr.
  • The noise comes from core/config.py:_load_raw, which logs once per absent config layer — every directory without a project-level deepcode_config.json.
  • LoggerConfig.level has no consumer, so the config offered no way to turn it down.

All three follow from the same missing call.

The ordering problem

Reading the config is itself one of the things that logs, so setup_logging(load_config().logger) would emit the very lines it is meant to suppress. A quiet default goes in first; the configured level is applied afterwards, and only when it differs from it.

DEEPCODE_LOG_LEVEL short-circuits both. It needs no config file, which makes it the escape hatch for debugging config loading itself, and it matches what deepcode mcp already honours.

One call site, not two

The report suggested cli/tui/app.py and cli/loop_cli.py. This lands in deepcode.main() instead: setup.py declares a single console_scripts entry (deepcode=deepcode:main) and that function dispatches all ten subcommands. Per-entrypoint calls would be the same block copied ten times, and the eleventh subcommand would forget it.

A broken config is caught and ignored here — logging is already usable at that point, and reporting a bad config properly is the subcommand's job.

Verification

From a directory with no project config:

sink level load_config() output
before 10 (loguru default) prints the DEBUG line
after, default 20 silent
after, DEEPCODE_LOG_LEVEL=DEBUG 10 prints it again

Five tests cover the sink level, the env override with no config present, a configured warning level, a malformed config, and that main() bootstraps before dispatching. Removing the call from main() fails the last one.

Full suite: 1223 passed, 3 skipped.

…inal

Reported in #167. loguru ships a stderr sink at DEBUG level and nothing on
the CLI path ever replaced it — `setup_logging()` was defined, exported and
documented, but never called. Confirmed by inspecting the handler table after
importing the CLI: one sink, id 0, level 10.

The visible symptom is the line `load_config` emits for each absent config
layer, which is every directory without a project-level deepcode_config.json:

    DEBUG | core.config:_load_raw:580 - deepcode_config.json not found at
    /Users/.../deepcode_config.json; skipping layer

The reporter also noted `LoggerConfig.level` had no consumer, so the config
offered no way to change this. Both follow from the same missing call.

Ordering is the awkward part, and the reason this is not one line: reading
the config is itself something that logs. So a quiet default goes in first,
and the configured level is applied afterwards only when it differs.
DEEPCODE_LOG_LEVEL short-circuits both, needs no config file, and matches
what `deepcode mcp` already honours — it is the escape hatch for debugging
config loading itself.

Placed in deepcode.main(), which is the sole console_scripts entry and
dispatches all ten subcommands. The report suggested the TUI and loop
entrypoints; putting it in each would be the same block copied ten times,
and the eleventh subcommand would forget it.

Verified from a directory with no project config: sink level moves 10 -> 20
and the DEBUG line stops, while DEEPCODE_LOG_LEVEL=DEBUG brings it back.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@Zongwei9888
Zongwei9888 merged commit 9740cea into main Aug 7, 2026
14 checks passed
@Zongwei9888
Zongwei9888 deleted the fix/cli-logging-setup branch August 7, 2026 08:45
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.

[Bug]: CLI prints DEBUG "deepcode_config.json not found... skipping layer" noise - setup_logging() never called by CLI entrypoints

1 participant