Skip to content

[duplicate-code] Duplicate Code Pattern: Dual stdlib/structured logging in launcher package #3209

@github-actions

Description

@github-actions

Part of duplicate code analysis: #3207

Summary

The same event is logged twice in rapid succession — once through the structured logger.LogXxxWithServer() helper (writes to structured file log) and once through Go's stdlib log.Printf("[LAUNCHER]...") (writes to stdout). This pattern recurs at least 5 times in internal/launcher/launcher.go.

Duplication Details

Pattern: Redundant dual-sink logging at each significant launcher event

  • Severity: High

  • Occurrences: 5+ paired call sites in internal/launcher/launcher.go

  • Locations:

    • internal/launcher/launcher.go lines 117–119
    • internal/launcher/launcher.go lines 144–146
    • internal/launcher/launcher.go lines 151–152
  • Code Sample:

// Lines 117–119: HTTP backend configured
logger.LogInfoWithServer(serverID, "backend", "Configuring HTTP MCP backend: %s, url=%s", serverID, serverCfg.URL)
log.Printf("[LAUNCHER] Configuring HTTP MCP backend: %s", serverID)
log.Printf("[LAUNCHER] URL: %s", serverCfg.URL)

// Lines 144–146: HTTP connection failed
logger.LogErrorWithServer(serverID, "backend", "Failed to create HTTP connection: %s, error=%v", serverID, err)
log.Printf("[LAUNCHER] ❌ FAILED to create HTTP connection for '%s'", serverID)
log.Printf("[LAUNCHER] Error: %v", err)

// Lines 151–152: HTTP backend success
logger.LogInfoWithServer(serverID, "backend", "Successfully configured HTTP MCP backend: %s", serverID)
log.Printf("[LAUNCHER] Successfully configured HTTP backend: %s", serverID)

Impact Analysis

  • Maintainability: Each message must be kept in sync across both sinks; a format or content change requires two edits.
  • Bug Risk: The two log lines can drift — e.g. serverCfg.URL is included in the structured log but not in the log.Printf equivalent at lines 118–119.
  • Code Bloat: ~15 extra lines of log.Printf calls that duplicate information already captured by the structured logger.
  • Consistency: The pattern is not uniform; some events only use one sink, making log coverage unpredictable.

Refactoring Recommendations

  1. Remove redundant log.Printf calls where logger.LogXxxWithServer already covers the same information. The structured file logger (plus logLauncher.Printf for debug details) is sufficient.
  2. Add stdout forwarding to the file logger if stdout visibility is required — this can be done once centrally in the logger initialisation rather than at every call site.
  3. Estimated effort: 30–60 minutes to remove the ~10 redundant log.Printf lines from launcher.go.

Implementation Checklist

  • Audit all log.Printf("[LAUNCHER]...") calls in launcher.go and log_helpers.go
  • Remove calls fully covered by an adjacent logger.LogXxxWithServer call
  • Verify remaining log.Printf calls (e.g. for OIDC warning at line 78–79) are intentional
  • Run make test to confirm no behaviour change

Parent Issue

See parent analysis report: #3207
Related to #3207

Generated by Duplicate Code Detector ·

  • expires on Apr 12, 2026, 6:03 AM UTC

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions