Skip to content

fix(logs): isolate non-default data-dir logs to <data-dir>/logs#660

Closed
Dumbris wants to merge 1 commit into
mainfrom
fix/mcp2255-isolate-non-default-logs
Closed

fix(logs): isolate non-default data-dir logs to <data-dir>/logs#660
Dumbris wants to merge 1 commit into
mainfrom
fix/mcp2255-isolate-non-default-logs

Conversation

@Dumbris

@Dumbris Dumbris commented Jun 14, 2026

Copy link
Copy Markdown
Member

Summary

Route a non-default data-dir's logs to <data-dir>/logs instead of the shared OS-standard location (~/Library/Logs/mcpproxy/ on macOS). This keeps Go test runs, e2e scripts, and FE/QA Playwright harnesses from polluting the production main.log.

Root cause

Forensics in MCP-2249: the phantom "core restarts every ~10s" was multiple test instances interleaving re-init lines in one shared log file. Every mcpproxy serve with a custom --data-dir wrote to the same ~/Library/Logs/mcpproxy/main.log because the log dir was derived purely from $HOME.

Design

Precedence (highest to lowest):

  1. --log-dir flag — always wins
  2. logging.log_dir in config
  3. <data-dir>/logs — only when data-dir is not the default (~/.mcpproxy)
  4. OS-standard location (unchanged for default data dir)

Default data dir (~/.mcpproxy) is unaffected — it still logs to the OS-standard location so the tray and documented paths keep working.

Files changed

  • cmd/mcpproxy/logdir.go — new: resolveServeLogDir(), defaultDataDirPath(), sameDir()
  • cmd/mcpproxy/logdir_test.go — new: 7 table-driven tests covering every branch
  • cmd/mcpproxy/main.go — replaces inline if cmdLogDir != "" override with resolveServeLogDir()
  • docs/logging.md — documents the new "Custom data directory" log location
  • internal/logs/e2e_test.go — updates e2e test to assert co-located path; adds negative assertion that OS-standard path is NOT written

Verification

  • go test ./cmd/mcpproxy/... -race -run TestResolveServeLogDir — 7/7 PASS
  • make build — compiles clean

Related #2255

The phantom "core restarts every ~10s" reports (MCP-2250, split from
MCP-2207) were a logging artifact, not a real restart loop. `serve`
enables file logging by default and derives the log dir purely from
$HOME (internal/logs.GetLogDir), ignoring --data-dir. So every
`mcpproxy serve` run — Go integration tests (temp data-dirs), e2e
scripts, FE/QA Playwright harnesses, AND the real prod core — appended
to the same ~/Library/Logs/mcpproxy/main.log. A reader of that shared
file saw dozens of fast, interleaved boots and concluded the core was
restarting every ~10s. Forensics on a 72-min window show only 2 real
prod-core boots (data_dir ~/.mcpproxy) among ~42, and every shutdown
was reason="signal" (no panics/self-restarts).

Fix: when the resolved data dir is non-default and no explicit
--log-dir was given, co-locate logs under <data-dir>/logs. The default
data dir (~/.mcpproxy) is unchanged and still logs to the OS-standard
location, so the tray and documented paths keep working. An explicit
--log-dir still wins.

- Add resolveServeLogDir helper (cmd/mcpproxy/logdir.go) with unit tests
  covering the full precedence: --log-dir > config log_dir >
  <data-dir>/logs (non-default) > OS-standard.
- Wire it into runServer (cmd/mcpproxy/main.go).
- Update TestE2E_MCPProxyWithLogging to assert the binary writes to
  <data-dir>/logs and does NOT leak into the shared OS-standard dir.
- Document the resolution order in docs/logging.md.

Related MCP-2250

Co-Authored-By: Paperclip <noreply@paperclip.ing>
@codecov-commenter

Copy link
Copy Markdown

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

❌ Patch coverage is 60.00000% with 8 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
cmd/mcpproxy/logdir.go 63.15% 6 Missing and 1 partial ⚠️
cmd/mcpproxy/main.go 0.00% 1 Missing ⚠️

📢 Thoughts on this report? Let us know!

@github-actions

Copy link
Copy Markdown

📦 Build Artifacts

Workflow Run: View Run
Branch: fix/mcp2255-isolate-non-default-logs

Available Artifacts

  • archive-darwin-amd64 (28 MB)
  • archive-darwin-arm64 (25 MB)
  • archive-linux-amd64 (16 MB)
  • archive-linux-arm64 (14 MB)
  • archive-windows-amd64 (28 MB)
  • archive-windows-arm64 (24 MB)
  • frontend-dist-pr (0 MB)
  • installer-dmg-darwin-amd64 (21 MB)
  • installer-dmg-darwin-arm64 (19 MB)

How to Download

Option 1: GitHub Web UI (easiest)

  1. Go to the workflow run page linked above
  2. Scroll to the bottom "Artifacts" section
  3. Click on the artifact you want to download

Option 2: GitHub CLI

gh run download 27498193228 --repo smart-mcp-proxy/mcpproxy-go

Note: Artifacts expire in 14 days.

@Dumbris

Dumbris commented Jun 14, 2026

Copy link
Copy Markdown
Member Author

Closing as a duplicate of #657. Both PRs carry byte-identical changes for MCP-2255 (log isolation for non-default data dirs); #657 is canonical (opened earlier, CI fully green, title/body reference MCP-2255). Consolidating on #657 to avoid two open PRs for the same fix.

@Dumbris Dumbris closed this Jun 14, 2026
@Dumbris Dumbris deleted the fix/mcp2255-isolate-non-default-logs branch June 14, 2026 13:43
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