Part of duplicate code analysis: #3309
Summary
internal/cmd/root.go contains ~10 consecutive pairs where the same startup event is logged twice — once to stdout via log.Printf and again to the structured logger via logger.LogInfoMd / logger.LogWarn. This pattern spans approximately 20 lines and introduces a maintenance burden: any message change must be applied in two places, creating a risk of divergence.
Duplication Details
Pattern: log.Printf + logger.LogXxxMd pairs for identical startup messages
- Severity: Medium
- Occurrences: ~10 pairs (≈20 affected lines)
- Location:
internal/cmd/root.go (lines 236–412)
- Code Sample:
// Pattern repeated ~10 times:
log.Printf("Guard policy override configured (source=%s)", policySource)
logger.LogInfoMd("startup", "Guard policy override configured (source=%s)", policySource)
log.Printf("MCP_GATEWAY_GUARDS_SINK_SERVER_IDS=%q", envSinkServerIDs)
logger.LogInfoMd("startup", "MCP_GATEWAY_GUARDS_SINK_SERVER_IDS=%q", envSinkServerIDs)
log.Printf("Guards sink server IDs configured for JSONL tag enrichment: %v", resolvedSinkServerIDs)
logger.LogInfoMd("startup", "Guards sink server IDs configured for JSONL tag enrichment: %v", resolvedSinkServerIDs)
log.Printf("Warning: guards sink server ID '%s' is not configured in mcpServers", sinkServerID)
logger.LogWarn("startup", "Guards sink server ID '%s' is not configured in mcpServers", sinkServerID)
log.Printf("Warning: failed to initialize tracing provider: %v", err)
logger.LogWarn("startup", "Failed to initialize tracing provider: %v", err)
log.Printf("Starting MCPG in ROUTED mode on %s", listenAddr)
logger.LogInfoMd("startup", "Starting in ROUTED mode on %s", listenAddr)
Impact Analysis
- Maintainability: Every message needs to be edited in two places; wording frequently diverges (e.g.
log.Printf("Warning: ...") vs logger.LogWarn(...)).
- Bug Risk: Diverged messages make log correlation harder during incident investigation.
- Code Bloat: ~20 lines that could be ~10.
Refactoring Recommendations
-
Extend logger.LogInfoMd / logger.LogWarnMd to also echo to stdout (or add a tee mode) so callers need only one call. The MarkdownLogger already writes to both file and markdown — adding a stdout tee for startup messages would eliminate the pair.
-
Alternatively, wrap the pair in a helper such as:
// internal/logger/startup.go
func StartupInfo(format string, args ...interface{}) {
log.Printf(format, args...)
LogInfoMd("startup", format, args...)
}
Estimated effort: 1–2 hours. Callers in root.go become single-line.
-
At minimum, remove the redundant log.Printf calls where logger.LogInfoMd already writes a sufficiently descriptive message, since the file logger also writes to stdout via its fallback path.
Implementation Checklist
Parent Issue
See parent analysis report: #3309
Related to #3309
Generated by Duplicate Code Detector · ● 2.2M · ◷
Part of duplicate code analysis: #3309
Summary
internal/cmd/root.gocontains ~10 consecutive pairs where the same startup event is logged twice — once to stdout vialog.Printfand again to the structured logger vialogger.LogInfoMd/logger.LogWarn. This pattern spans approximately 20 lines and introduces a maintenance burden: any message change must be applied in two places, creating a risk of divergence.Duplication Details
Pattern:
log.Printf+logger.LogXxxMdpairs for identical startup messagesinternal/cmd/root.go(lines 236–412)Impact Analysis
log.Printf("Warning: ...")vslogger.LogWarn(...)).Refactoring Recommendations
Extend
logger.LogInfoMd/logger.LogWarnMdto also echo to stdout (or add ateemode) so callers need only one call. TheMarkdownLoggeralready writes to both file and markdown — adding a stdout tee for startup messages would eliminate the pair.Alternatively, wrap the pair in a helper such as:
Estimated effort: 1–2 hours. Callers in
root.gobecome single-line.At minimum, remove the redundant
log.Printfcalls wherelogger.LogInfoMdalready writes a sufficiently descriptive message, since the file logger also writes to stdout via its fallback path.Implementation Checklist
internal/logger/internal/cmd/root.goto use the new helper (~10 sites)make agent-finishedParent Issue
See parent analysis report: #3309
Related to #3309