← Back to PRs

#11153: refactor(hooks): replace console.warn/error with subsystem logger

by hclsys open 2026-02-07 13:25 View on GitHub →
stale
## Summary Replace remaining `console.warn`/`console.error` calls in the hooks subsystem with `createSubsystemLogger`, completing the migration pattern established in #10730. - **workspace.ts**: 2× `console.warn` → `log.warn` (hook discovery warnings) - **internal-hooks.ts**: 1× `console.error` → `log.error` (hook dispatch error) - **llm-slug-generator.ts**: 1× `console.error` → `log.error` (slug generation failure) - **internal-hooks.test.ts**: Updated error handler test to assert behavior (error isolation) rather than log output format ## Risk Summary | Category | Risk | Rationale | |:---------|:-----|:----------| | Correctness | None | Drop-in replacement, identical semantics | | Performance | None | No hot path changes | | Breaking changes | None | Internal logging only, no public API | ## Changes All four `console.warn`/`console.error` calls follow the same transformation: 1. Add `import { createSubsystemLogger }` and `const log = createSubsystemLogger("hooks/<name>")` 2. Replace `console.warn(msg)` → `log.warn(msg)` and `console.error(msg)` → `log.error(msg)` 3. Inline error objects as strings since `SubsystemLogger` expects `(message: string, meta?: Record<string, unknown>)` — not raw `Error` objects 4. Remove redundant `[hooks]` / `[llm-slug-generator]` manual prefixes (subsystem logger adds these automatically) ## Verification - [ ] `pnpm test -- src/hooks/internal-hooks.test.ts` passes - [ ] `pnpm format` passes (verified locally with `oxfmt --check`) - [ ] No remaining `console.warn`/`console.error` in modified files (verified via grep) ## Sign-Off | Field | Value | |:------|:------| | Models used | Claude Opus 4.6, OpenAI Codex (plan + code review) | | Submitter effort | Identified pattern from merged #10730, audited all hooks files, converted 4 calls across 3 source files + 1 test file | | Agent notes | Codex flagged SubsystemLogger signature mismatch (Error objects vs string) — addressed by inlining `err instanceof Error ? err.message : String(err)`. Codex also caught test regression in internal-hooks.test.ts line 135-137 — test updated to assert behavior not format. | lobster-biscuit --- *Generated with [Claude Code](https://claude.ai/code)* <!-- greptile_comment --> <h2>Greptile Overview</h2> <h3>Greptile Summary</h3> This PR finishes migrating the hooks subsystem off direct `console.warn/error` calls and onto the shared `createSubsystemLogger` API. - `src/hooks/workspace.ts` now logs hook discovery/load warnings via a hooks/workspace subsystem logger. - `src/hooks/internal-hooks.ts` now logs handler dispatch errors via a hooks/internal subsystem logger. - `src/hooks/llm-slug-generator.ts` now logs slug generation failures via a hooks/llm-slug-generator subsystem logger. - `src/hooks/internal-hooks.test.ts` was updated to assert the key behavior (handler errors don’t prevent subsequent handlers) rather than matching exact console output. <h3>Confidence Score: 4/5</h3> - This PR is likely safe to merge, with a small test-isolation concern to address. - The code changes are straightforward logging substitutions and preserve the existing control flow (errors still get caught and don’t abort subsequent handlers). The main remaining concern is the updated test muting all console methods, which can hide logging regressions and reduces the signal the test provides. - src/hooks/internal-hooks.test.ts <!-- greptile_other_comments_section --> <!-- /greptile_comment -->

Most Similar PRs