Skip to content

Find and replace console.logs to use logger.ts - #149

Merged
Avni2000 merged 2 commits into
mainfrom
105-convert-all-consolelogs-to-loggerts
Mar 1, 2026
Merged

Avni2000 merged 2 commits into
mainfrom
105-convert-all-consolelogs-to-loggerts

Conversation

@Avni2000

@Avni2000 Avni2000 commented Mar 1, 2026 •

Copy link
Copy Markdown
Owner
  • Use console.logs in testing files for CI
  • Add production/development env vars in esbuild

Summary by CodeRabbit

Release Notes

  • New Features

    • NODE_ENV is now available in the browser bundle for environment-specific logic.
    • WebSocket hook now provides expanded state information including session ID, conflict data, and resolution status.
  • Refactor

    • Centralized logging system for improved consistency and debuggability across all components.
    • Debug logging now enabled in CI and test environments in addition to development mode.

- Use console.logs in testing files for CI
- Add production/development env vars in esbuild
@Avni2000 Avni2000 linked an issue Mar 1, 2026 that may be closed by this pull request
@coderabbitai

coderabbitai Bot commented Mar 1, 2026 •

Copy link
Copy Markdown
Contributor

Warning

Rate limit exceeded

@Avni2000 has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 7 minutes and 54 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

📥 Commits

Reviewing files that changed from the base of the PR and between ca7890a and 3939167.

📒 Files selected for processing (1)
  • src/logger.ts
📝 Walkthrough

Walkthrough

This pull request centralizes logging across the codebase by replacing direct console calls with a centralized logger module. Additionally, the logger.ts module is updated to enable debug logging under new conditions (CI=true, NODE_ENV=test) and removes message prefixes. The esbuild configuration is updated to propagate NODE_ENV to the browser bundle, and the useWebSocket.ts interface is expanded with new state fields.

Changes

Cohort / File(s) Summary
Logging Centralization
src/extension.ts, src/gitIntegration.ts, src/conflictDetector.ts, src/resolver.ts
Replaced console.log/warn/error calls with corresponding logger.* methods across core modules; no control flow changes.
Web Server & Client Logging
src/web/webServer.ts, src/web/WebConflictPanel.ts, src/web/client/CellContent.tsx, src/web/client/index.tsx, src/web/client/markdown.ts
Replaced console logging with logger.* equivalents in HTTP/WebSocket lifecycle and error handling paths.
WebSocket Interface Expansion
src/web/client/useWebSocket.ts
Expanded UseWebSocketResult interface to include sessionId, conflictData, sendMessage, resolutionStatus, and resolutionMessage; added logger imports and replaced console calls.
Logger Module Enhancement
src/logger.ts
Updated debug logging to activate under additional conditions (CI=true, NODE_ENV=test); removed [MergeNB] prefix; changed log output to use plain console methods.
Build Configuration
esbuild.js
Added define option to propagate process.env.NODE_ENV to browser bundle based on production flag.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~22 minutes

Possibly related PRs

Poem

🐰 Console logs fade to history's page,
A logger rises to center stage!
Debug conditions bloom anew,
WebSocket riches break on through—
The refactored code hops bright and clean! ✨

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 34.62% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title '[REFACTOR] Find and replace console.logs to use logger.ts' clearly and accurately summarizes the main objective of the changeset: migrating console logging to a centralized logger module across multiple files.

✏️ 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
  • Commit unit tests in branch 105-convert-all-consolelogs-to-loggerts

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.

@Avni2000 Avni2000 changed the title [REFACTOR] Find and replace console.logs to use logger.ts Find and replace console.logs to use logger.ts Mar 1, 2026

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🧹 Nitpick comments (1)
src/web/client/useWebSocket.ts (1)

49-49: Avoid logging full WebSocket payload objects.

Line 49 currently logs the entire parsed message; conflict-data payloads can be large and may contain sensitive notebook content. Prefer logging only message kind (type/command).

💡 Suggested change
-                logger.debug('[MergeNB] Received:', msg);
+                const messageLabel =
+                    'type' in msg
+                        ? `type=${msg.type}`
+                        : 'command' in msg
+                            ? `command=${msg.command}`
+                            : 'unknown';
+                logger.debug(`[MergeNB] Received WebSocket message (${messageLabel})`);
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/web/client/useWebSocket.ts` at line 49, The current logger.debug in
useWebSocket logs the full parsed WebSocket message object (msg) which can
include large/sensitive `conflict-data`; change it to log only the message
kind/type/command instead of the full payload: in the useWebSocket handler
replace the logger.debug('[MergeNB] Received:', msg) usage with a log that
extracts and logs a single identifying field (e.g., msg.kind or msg.type or
msg.command, whichever the protocol uses) and avoid including msg.payload or
other full data fields; if the identifying field may be missing, guard and log a
fallback like '[unknown]'.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@src/logger.ts`:
- Around line 19-24: The isDebugEnabled function reads process.env unguarded and
throws in browsers; update isDebugEnabled to first check typeof process !==
'undefined' && process.env before accessing variables (e.g., guard checks for
__VSCODE_EXTENSION_DEVELOPMENT__, CI, NODE_ENV), returning false if process or
process.env is missing; modify the logger.debug callers need not change—only
update isDebugEnabled in logger.ts to safely read environment flags.

In `@src/web/client/useWebSocket.ts`:
- Line 8: The logger currently reads
process.env.__VSCODE_EXTENSION_DEVELOPMENT__ and process.env.CI directly inside
isDebugEnabled(), which throws in browser bundles; change isDebugEnabled() to
guard those reads with typeof checks (e.g., typeof process !== 'undefined' &&
typeof process.env !== 'undefined' && typeof
process.env.__VSCODE_EXTENSION_DEVELOPMENT__ !== 'undefined') before accessing
them, or alternately add definitions for __VSCODE_EXTENSION_DEVELOPMENT__ and CI
in the web build define map used for the client bundle; update the
logger.isDebugEnabled() function to use the guarded access so the web client
import of logger no longer triggers ReferenceError.

---

Nitpick comments:
In `@src/web/client/useWebSocket.ts`:
- Line 49: The current logger.debug in useWebSocket logs the full parsed
WebSocket message object (msg) which can include large/sensitive
`conflict-data`; change it to log only the message kind/type/command instead of
the full payload: in the useWebSocket handler replace the
logger.debug('[MergeNB] Received:', msg) usage with a log that extracts and logs
a single identifying field (e.g., msg.kind or msg.type or msg.command, whichever
the protocol uses) and avoid including msg.payload or other full data fields; if
the identifying field may be missing, guard and log a fallback like '[unknown]'.

ℹ️ Review info

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 3ada516 and ca7890a.

📒 Files selected for processing (12)
  • esbuild.js
  • src/conflictDetector.ts
  • src/extension.ts
  • src/gitIntegration.ts
  • src/logger.ts
  • src/resolver.ts
  • src/web/WebConflictPanel.ts
  • src/web/client/CellContent.tsx
  • src/web/client/index.tsx
  • src/web/client/markdown.ts
  • src/web/client/useWebSocket.ts
  • src/web/webServer.ts

Comment thread src/logger.ts Resolved
Comment thread src/web/client/useWebSocket.ts Resolved
- Address coderabbit comments
@Avni2000
Avni2000 merged commit 755ab91 into main Mar 1, 2026
5 checks passed
@Avni2000
Avni2000 deleted the 105-convert-all-consolelogs-to-loggerts branch March 20, 2026 20:20
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.

Convert all console.logs to logger.ts

1 participant