{"record":{"id":"638e0ab2f149aa35","repo":"flipped-aurora/gin-vue-admin","slug":"panic-err-standalone-mcp-logger-init-failed","errorCode":null,"errorMessage":"panic(err) — standalone MCP logger init failed","messagePattern":"panic\\(err\\) — standalone MCP logger init failed","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"server/cmd/mcp/main.go","lineNumber":19,"sourceCode":"package main\n\nimport (\n\t\"fmt\"\n\n\t\"github.com/flipped-aurora/gin-vue-admin/server/global\"\n\tmcpTool \"github.com/flipped-aurora/gin-vue-admin/server/mcp\"\n\t\"github.com/flipped-aurora/gin-vue-admin/server/utils/logger\"\n\t_ \"go.uber.org/automaxprocs\"\n)\n\nfunc main() {\n\tconfigPath, err := loadStandaloneConfig()\n\tif err != nil {\n\t\tpanic(err)\n\t}\n\n\tif err := initializeStandaloneLogger(); err != nil {\n\t\tpanic(err)\n\t}\n\n\taddr := fmt.Sprintf(\":%d\", global.GVA_CONFIG.MCP.Addr)\n\tserver := mcpTool.NewStreamableHTTPServer()\n\n\tlogger.Bg().Mod(\"cli\").\n\t\tField(\"config\", configPath).\n\t\tField(\"addr\", addr).\n\t\tField(\"path\", global.GVA_CONFIG.MCP.Path).\n\t\tField(\"upstream\", global.GVA_CONFIG.MCP.UpstreamBaseURL).\n\t\tInfo(\"mcp独立服务启动\")\n\n\tif err := server.Start(addr); err != nil {\n\t\tlogger.Bg().Mod(\"cli\").Err(err).Error(\"mcp独立服务启动失败\")\n\t\tpanic(err)\n\t}\n}\n","sourceCodeStart":1,"sourceCodeEnd":37,"githubUrl":"https://github.com/flipped-aurora/gin-vue-admin/blob/3136500ef380842b0eb6c4daa87c3f8a47fcf9e0/server/cmd/mcp/main.go#L1-L37","documentation":"After config loads, the standalone MCP server initializes its logger; failure (e.g. cannot create/open the log file or bad logger config) triggers panic(err), aborting startup. This guarantees the service never runs without observability.","triggerScenarios":"initializeStandaloneLogger returns an error: log directory does not exist or is unwritable, log file path invalid, or logger stack initialization fails for the loaded config.","commonSituations":"Docker container with read-only filesystem and no writable log dir; log path pointing to a directory deleted after deploy; running as non-root user lacking write access to the configured log path.","solutions":["Check the configured log directory exists and is writable by the process user (mkdir -p, chown)","Point the log output to stdout/stderr or a writable path in containers","Verify logger-related config keys are valid","Re-run the binary after fixing permissions"],"exampleFix":"// before\nlogs: /var/log/gva/mcp.log  # dir missing\n// after\nmkdir -p /var/log/gva && chown app:app /var/log/gva","handlingStrategy":"validation","validationCode":"logDir := filepath.Dir(logPath); if err := os.MkdirAll(logDir, 0o755); err != nil { log.Fatalf(\"cannot create log dir: %v\", err) }","typeGuard":null,"tryCatchPattern":"if err := initializeStandaloneLogger(); err != nil { log.Printf(\"logger init failed: %v\", err); os.Exit(1) } // or recover in a supervisor wrapper","preventionTips":["Ensure the log directory exists and is writable by the service user before startup","In containers, log to stdout/stderr instead of files","Create log dirs in the entrypoint script (mkdir -p)","Verify permissions after deploys as a non-root user"],"tags":["logging","startup","panic","mcp"],"backgroundTag":"log-file-not-writable","analyzedSha":"3136500ef380842b0eb6c4daa87c3f8a47fcf9e0","analyzedAt":"2026-08-31T13:50:02.721Z","schemaVersion":2},"datasetVersion":"2026-08-31T19:17:28.585Z"}