#11153: refactor(hooks): replace console.warn/error with subsystem logger
stale
Cluster:
Hooks and UI Fixes
## 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
#3392: fix(hooks): remove debug console.log statements from session-memory...
by WinJayX · 2026-01-28
84.9%
#23669: refactor(logging): migrate node-host and tailscale console calls to...
by kevinWangSheng · 2026-02-22
83.4%
#11549: lint: add no-console rule and migrate 5 files to structured logger
by vaibhavtupe · 2026-02-08
81.7%
#11817: fix(build): compile bundled hook handlers into dist
by AnonO6 · 2026-02-08
81.4%
#15571: feat: infrastructure foundation — hooks, model failover, sessions, ...
by tangcruz · 2026-02-13
79.0%
#9425: refactor(agents): replace console.warn with SubsystemLogger in comp...
by dinakars777 · 2026-02-05
79.0%
#16915: fix: await compaction hooks with timeout to prevent cross-session d...
by maximalmargin · 2026-02-15
78.2%
#9914: fix(hooks): resolve bundled hook dist paths and packaging checks
by zimmra · 2026-02-05
78.0%
#9974: refactor(agents): replace console.warn with SubsystemLogger in comp...
by dinakars777 · 2026-02-05
78.0%
#19922: feat(hooks): add message:received and message:sent hook events
by NOVA-Openclaw · 2026-02-18
77.3%