Skip to content

Conversation

brettimus
Copy link
Collaborator

@brettimus brettimus commented Oct 8, 2025

Implement package-level logging to enable debugging without interfering with the TUI. Logs are written to ~/.mcp-gateway/logs/ as JSON lines with daily rotation and automatic cleanup.

Changes:

  • Add logger module (src/logger.ts) with debug/info/warn/error levels
  • Daily log rotation: one file per day (gateway-YYYY-MM-DD.log)
  • Automatic cleanup of logs older than 30 days
  • Initialize logger in run.ts and server/index.ts for all entry points
  • Replace console.warn/error calls with logger throughout codebase
  • Remove console.log statements from TUI effects (won't display anyway)
  • Keep user-facing console output (help, version, startup messages)

Log entries include ISO 8601 timestamp, level, message, and optional context object for structured debugging in production.


Note

Add structured file-based logging (JSONL, daily rotation, 30‑day cleanup) and replace console usage across server/CLI, proxy, capture, and tools.

  • Logging (new):
    • Add src/logger.ts with debug/info/warn/error, JSONL output, daily file rotation (gateway-YYYY-MM-DD.log), and 30‑day cleanup.
    • Respect LOG_LEVEL env; no-throw, test-aware behavior.
  • Server/CLI Integration:
    • Initialize logger in src/run.ts and src/server/index.ts; add Hono logger middleware in server/create-server.ts.
    • Add dev:server script; print essential user messages only.
  • Capture/Proxy/MCP:
    • Replace console.* with logger in capture.ts, mcp-server.ts, mcp-tools/capture-tools.ts, and server/create-proxy-routes.ts with structured context.
    • Improve error reporting in appendCapture (include filePath), SSE capture paths, and MCP middleware/handler.
  • TUI:
    • Remove transient console.log messages in tui/effects.ts; keep UI-driven feedback.
  • Config:
    • Lint rules: add suspicious.noConsole=warn; adjust workspace scripts to biome ci/biome check --write.
  • Tests:
    • Add comprehensive tests/logger.test.ts; annotate existing tests to ignore console linting.

Written by Cursor Bugbot for commit 20670d7. This will update automatically on new commits. Configure here.

Implement package-level logging to enable debugging without interfering
with the TUI. Logs are written to ~/.mcp-gateway/logs/ as JSON lines
with daily rotation and automatic cleanup.

Changes:
- Add logger module (src/logger.ts) with debug/info/warn/error levels
- Daily log rotation: one file per day (gateway-YYYY-MM-DD.log)
- Automatic cleanup of logs older than 30 days
- Initialize logger in run.ts and server/index.ts for all entry points
- Replace console.warn/error calls with logger throughout codebase
- Remove console.log statements from TUI effects (won't display anyway)
- Keep user-facing console output (help, version, startup messages)

Log entries include ISO 8601 timestamp, level, message, and optional
context object for structured debugging in production.
@brettimus
Copy link
Collaborator Author

@codex review

cursor[bot]

This comment was marked as outdated.

Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

@brettimus brettimus changed the title Aadd file-based logging system for mcp-gateway CLI/server logs with daily rotation Add file-based logging system for mcp-gateway CLI/server logs with daily rotation Oct 8, 2025
cursor[bot]

This comment was marked as outdated.

cursor[bot]

This comment was marked as outdated.

Copy link
Member

@flenter flenter left a comment

Choose a reason for hiding this comment

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

Nice. This made me look at our biome/linting setup and i think it's currently not working correctly.

We should configure biome to give warnings when console..logs are used:

// In the biome.jsonc we should expand the suspicious section to warn about it
      "suspicious": { "noExplicitAny": "error", "noConsole": "warn" },

And i don't think we're running the right biome commands either, the script section of the package json should be updated to complain a bit more during linting and do a bit of linting during formatting.

I was also wondering why we'd roll our own file based logging solution but the logger in this PR is still fairly straightforward (and configuring other loggers can be a bit of a pain)

-    "lint": "biome check --write .",
-    "format": "biome format --write .",
+    "lint": "biome ci .",
+    "format": "biome check --write .",

@brettimus
Copy link
Collaborator Author

Nice. This made me look at our biome/linting setup and i think it's currently not working correctly.

We should configure biome to give warnings when console..logs are used:

// In the biome.jsonc we should expand the suspicious section to warn about it
      "suspicious": { "noExplicitAny": "error", "noConsole": "warn" },

And i don't think we're running the right biome commands either, the script section of the package json should be updated to complain a bit more during linting and do a bit of linting during formatting.

I was also wondering why we'd roll our own file based logging solution but the logger in this PR is still fairly straightforward (and configuring other loggers can be a bit of a pain)

-    "lint": "biome check --write .",
-    "format": "biome format --write .",
+    "lint": "biome ci .",
+    "format": "biome check --write .",

i'll tackle the biome improvements!

@brettimus brettimus merged commit e2ae057 into main Oct 9, 2025
2 checks passed
@brettimus brettimus deleted the add-package-level-logging branch October 9, 2025 12:02
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.

2 participants