You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Across the internal/server package, there is a recurring pattern where typed debug loggers (e.g., logRouted, logUnified) were added alongside existing log.Printf calls for the same event, rather than replacing them. This pattern exists in at least 3 files and represents an ongoing maintenance risk as new debug loggers are added.
Duplication Details
Pattern: Typed debug logger + stdlib log.Printf for same event
log.Printf("Creating filtered server for %s with %d tools", backendID, len(tools))
logRouted.Printf("Backend %s has %d tools available", backendID, len(tools))
Both lines describe the same event (a filtered server being created with N tools) but with slightly different wording. Neither is clearly superior.
unified.go — callBackendTool (lines 268–269)
log.Printf("Calling tool on %s: %s with DIFC enforcement", serverID, toolName)
logUnified.Printf("callBackendTool: serverID=%s, toolName=%s, args=%+v", serverID, toolName, args)
Same event (tool invocation), logged to both loggers. The debug logger adds args which is valuable; the stdlib logger provides a summary message.
unified.go — NewUnifiedServer (lines 176, 181)
logUnified.Printf("Auto-enabled DIFC: non-noop guard, global policy, or per-server guard policies detected")
log.Printf("Guards enforcement enabled with mode: %s", cfg.DIFCMode)
Same initialization event (DIFC/guards enabled), split across two nearby log calls.
Impact Analysis
Maintainability: When updating log messages, developers must check both logger types; message divergence has already begun (different wording for same event)
Log Verbosity: Production deployments receive double log entries for hot paths like callBackendTool, which is called for every MCP tool invocation
Inconsistency: Some files have migrated to typed debug loggers (e.g., auth.go, health.go, response_writer.go) while others retain the dual pattern, making the logging strategy unclear
Establish a clear convention: Debug loggers (logXxx.Printf) should replace not supplement log.Printf for the same event. The debug logger (when DEBUG=* is active) replaces verbosity; the file logger handles persistence.
Consolidate routed.go lines 132–133:
// Before (two lines, same event):log.Printf("Creating filtered server for %s with %d tools", backendID, len(tools))
logRouted.Printf("Backend %s has %d tools available", backendID, len(tools))
// After (one debug log, one operational log if needed):logRouted.Printf("Creating filtered server: backend=%s, tools=%d", backendID, len(tools))
Update AGENTS.md to document the convention: debug loggers replace log.Printf for the same events; logger.LogInfo/Warn/Error is used for operational/persistent logging.
Estimated effort: ~1 hour for targeted cleanup of the identified dual-log pairs; longer if the full server package is audited
Implementation Checklist
Decide on authoritative logging convention (debug logger replaces stdlib log for same event)
Consolidate routed.go lines 132–133 into single logRouted.Printf
Consolidate unified.go lines 268–269 into single logUnified.Printf
Review and consolidate unified.go lines 176/181
Audit remaining log.Printf calls in internal/server/*.go for additional dual-log pairs
Document convention in AGENTS.md or a logging guide
Run make agent-finished to verify no regressions
Parent Issue
See parent analysis report: #2711
Related to #2711
Part of duplicate code analysis: #2711
Summary
Across the
internal/serverpackage, there is a recurring pattern where typed debug loggers (e.g.,logRouted,logUnified) were added alongside existinglog.Printfcalls for the same event, rather than replacing them. This pattern exists in at least 3 files and represents an ongoing maintenance risk as new debug loggers are added.Duplication Details
Pattern: Typed debug logger + stdlib
log.Printffor same eventinternal/server/routed.go,internal/server/unified.gorouted.go—createFilteredServer(lines 132–133)Both lines describe the same event (a filtered server being created with N tools) but with slightly different wording. Neither is clearly superior.
unified.go—callBackendTool(lines 268–269)Same event (tool invocation), logged to both loggers. The debug logger adds
argswhich is valuable; the stdlib logger provides a summary message.unified.go—NewUnifiedServer(lines 176, 181)Same initialization event (DIFC/guards enabled), split across two nearby log calls.
Impact Analysis
callBackendTool, which is called for every MCP tool invocationauth.go,health.go,response_writer.go) while others retain the dual pattern, making the logging strategy unclearlogSession, suggesting no team-wide convention has been establishedRefactoring Recommendations
Establish a clear convention: Debug loggers (
logXxx.Printf) should replace not supplementlog.Printffor the same event. The debug logger (whenDEBUG=*is active) replaces verbosity; the file logger handles persistence.Consolidate
routed.golines 132–133:Consolidate
unified.golines 268–269:Update AGENTS.md to document the convention: debug loggers replace
log.Printffor the same events;logger.LogInfo/Warn/Erroris used for operational/persistent logging.Estimated effort: ~1 hour for targeted cleanup of the identified dual-log pairs; longer if the full server package is audited
Implementation Checklist
routed.golines 132–133 into singlelogRouted.Printfunified.golines 268–269 into singlelogUnified.Printfunified.golines 176/181log.Printfcalls ininternal/server/*.gofor additional dual-log pairsmake agent-finishedto verify no regressionsParent Issue
See parent analysis report: #2711
Related to #2711