Skip to content

refactor(logging): replace console calls with Winston logger in server files#289

Open
Muneerali199 wants to merge 1 commit intoAOSSIE-Org:mainfrom
Muneerali199:refactor/server-logging-v2
Open

refactor(logging): replace console calls with Winston logger in server files#289
Muneerali199 wants to merge 1 commit intoAOSSIE-Org:mainfrom
Muneerali199:refactor/server-logging-v2

Conversation

@Muneerali199
Copy link
Contributor

@Muneerali199 Muneerali199 commented Mar 12, 2026

Closes #213

What changed

Replaced all raw console.log/warn/error calls in the server-side files with the existing Winston logger from src/utils/logger.ts.

Files modified:

  • src/server/InputHandler.ts — added logger import, replaced ~12 console calls, redacted raw key content from debug logs, fixed error objects passed directly instead of interpolated as strings, fixed dead catch block in scroll handler to actually log rejections
  • src/server/ydotool.ts — replaced 3 console calls, included the caught err in the logger.warn call so it isn't swallowed
  • src/server/tokenStore.ts — replaced console.error with logger.error, passing the Error object directly
  • src/server/websocket.ts — removed duplicate console.error next to logger.error, fixed error interpolation on 3 calls, downgraded high-frequency "Upgrade request received" log from info to debug
  • src/utils/logger.ts — removed unused _originalConsoleLog/_originalConsoleError variables and the dead console interception block

What was not changed

  • electron/main.cjs — CJS module, cannot import the TypeScript logger
  • src/routes/settings.tsx — frontend file, out of scope for this issue

Security note

Raw keystroke content (msg.key) is not logged at any level. Debug messages use redacted placeholders to avoid leaking passwords or sensitive input character-by-character into log files.

Summary by CodeRabbit

  • Refactor
    • Improved logging infrastructure across server components by adopting a centralized logger with structured error handling and better message formatting.
    • Streamlined logging mechanism to provide more consistent and reliable error reporting and debugging information.

- Replace all console.log/warn/error in InputHandler.ts, ydotool.ts,
  tokenStore.ts with the centralized Winston logger
- Remove duplicate console.error next to logger.error in websocket.ts
- Pass Error objects directly to logger.error() to preserve stack traces
- Redact raw key/combo content from debug logs to prevent keystroke leakage
- Include caught error in ydotool warn call for better diagnostics
- Downgrade high-frequency upgrade-request log from info to debug
- Remove unused console interception block from logger.ts

Closes AOSSIE-Org#213
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Mar 12, 2026

Walkthrough

This change refactors server-side logging by systematically replacing console-based logging (console.log, console.error, console.warn) with a centralized logger module across five server files. Additionally, the console override shim in the logger utility is removed, shifting from runtime console interception to explicit logger usage at call sites.

Changes

Cohort / File(s) Summary
Server Input & Control
src/server/InputHandler.ts, src/server/ydotool.ts
Replaced console logging with logger calls (debug, info, warn, error) for mouse movement, key presses, and input event handling; preserved async behavior and fallback logic.
Server Persistence & WebSocket
src/server/tokenStore.ts, src/server/websocket.ts
Switched console.error to structured logger.error with error objects; downgraded "Upgrade request" info log to debug level; maintained error handling semantics.
Logger Utility
src/utils/logger.ts
Removed runtime console.log/console.error override shim; preserved Winston logger setup and conditional Console transport.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~13 minutes

Possibly related PRs

  • #209: Modifies InputHandler.ts and ydotool.ts with concurrent mouse-move handling path updates.
  • #168: Directly related changes to logger.ts console override handling and Winston serialization.
  • #181: Shares InputHandler.ts and websocket.ts modifications affecting server logging and input configuration.

Suggested labels

Typescript Lang

Poem

🐰 Console logs fade to whispers now,
A logger module shows us how—
Winston captures every trace,
No more shims to intercede,
Clean refactoring fills the space! ✨

🚥 Pre-merge checks | ✅ 4
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately summarizes the main change: refactoring logging to replace console calls with Winston logger across server files.
Description check ✅ Passed The description clearly explains what changed, which files were modified, what was not changed, and includes a security note about not logging sensitive data.
Linked Issues check ✅ Passed The PR successfully addresses all objectives from issue #213: removes console logging outside websocket.ts, cleans up websocket.ts logs, downgrades high-frequency logs, and protects sensitive keystroke data from logging.
Out of Scope Changes check ✅ Passed All changes are directly aligned with issue #213 objectives. The PR properly excludes out-of-scope files (electron/main.cjs and src/routes/settings.tsx) and focuses only on server-side logging refactoring.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
src/server/InputHandler.ts (1)

263-277: ⚠️ Potential issue | 🟡 Minor

Make the shared logger level configurable.

The logger in src/utils/logger.ts hardcodes level: "info", which suppresses the new logger.debug() calls at lines 263, 277, 317, and 340. These debugging breadcrumbs are unavailable in every environment unless the logger level is changed.

Suggested fix in src/utils/logger.ts
-	level: "info",
+	level: process.env.LOG_LEVEL ?? (process.env.NODE_ENV === "production" ? "info" : "debug"),
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/server/InputHandler.ts` around lines 263 - 277, The shared logger is
hardcoded to level "info" so the new logger.debug() calls (e.g., in InputHandler
using logger.debug) are never emitted; update the logger factory (the exported
logger object created in utils/logger.ts, e.g., createLogger or default exported
logger) to accept/configure its level from an environment/config variable (for
example process.env.LOG_LEVEL) or a passed option and default to "info", then
use that configurable level when instantiating/creating the logger so debug
messages from InputHandler and other modules are emitted when the level is set
to "debug".
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Outside diff comments:
In `@src/server/InputHandler.ts`:
- Around line 263-277: The shared logger is hardcoded to level "info" so the new
logger.debug() calls (e.g., in InputHandler using logger.debug) are never
emitted; update the logger factory (the exported logger object created in
utils/logger.ts, e.g., createLogger or default exported logger) to
accept/configure its level from an environment/config variable (for example
process.env.LOG_LEVEL) or a passed option and default to "info", then use that
configurable level when instantiating/creating the logger so debug messages from
InputHandler and other modules are emitted when the level is set to "debug".

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Run ID: 21c3ed6a-2261-4a76-a621-c49e42757ef7

📥 Commits

Reviewing files that changed from the base of the PR and between a3fbad4 and f480207.

📒 Files selected for processing (5)
  • src/server/InputHandler.ts
  • src/server/tokenStore.ts
  • src/server/websocket.ts
  • src/server/ydotool.ts
  • src/utils/logger.ts
💤 Files with no reviewable changes (1)
  • src/utils/logger.ts

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.

Refactor Server-Side Logging

1 participant