Skip to content

[log] config: migrate logConfig from legacy log.New to project debug logger#3372

Merged
lpcox merged 1 commit intomainfrom
log/config-core-debug-logger-aca44b5a3cdcafd8
Apr 11, 2026
Merged

[log] config: migrate logConfig from legacy log.New to project debug logger#3372
lpcox merged 1 commit intomainfrom
log/config-core-debug-logger-aca44b5a3cdcafd8

Conversation

@github-actions
Copy link
Copy Markdown
Contributor

@github-actions github-actions bot commented Apr 8, 2026

Summary

Migrates internal/config/config_core.go from the legacy log.New pattern to the project's standard debug logger (logger.New).

Changes

File modified: internal/config/config_core.go

Before

import (
    "fmt"
    "io"
    "log"
    "os"
    ...
)

// logger for config package
var logConfig = log.New(io.Discard, "[CONFIG] ", log.LstdFlags)

// SetDebug enables debug logging for config package
func SetDebug(enabled bool) {
    if enabled {
        logConfig = log.New(os.Stderr, "[CONFIG] ", log.LstdFlags)
    } else {
        logConfig = log.New(io.Discard, "[CONFIG] ", log.LstdFlags)
    }
}

After

import (
    "fmt"
    "os"
    ...
    "github.com/github/gh-aw-mcpg/internal/logger"
)

// logConfig is the debug logger for the config package.
// Enable with DEBUG=config:* or DEBUG=*.
var logConfig = logger.New("config:config")

Motivation

The config package was the last package in internal/ still using the legacy log.New(io.Discard, ...) pattern. This pattern required explicit SetDebug(true) calls (which were never made anywhere in the codebase) to see any output.

The project's logger.New pattern:

  • Is controlled by the DEBUG env var (e.g. DEBUG=config:* or DEBUG=*)
  • Writes colorized, time-diff output to stderr during development
  • Also writes to the file logger (mcp-gateway.log) for production troubleshooting
  • Is consistent with all other packages in the codebase

Impact

  • The existing logConfig.Printf(...) calls in both config_core.go and config_stdin.go now route through the project's debug logger
  • SetDebug is removed (was never called; no callers exist)
  • io and log standard library imports removed from config_core.go
  • Zero behavioral change in production (debug logs only appear when DEBUG env var matches)

Testing

  • Build: go build ./... (no compilation errors)
  • Tests: go test ./... (no regressions)
  • Vet: go vet ./... (no issues)

Generated by Go Logger Enhancement · ● 5.8M ·

Replace the legacy standard-library logger (log.New discarding by
default, toggled via SetDebug) with the project's debug logger pattern
(logger.New). This makes config package debug output consistent with
the rest of the codebase:

- Controlled via DEBUG env var (e.g. DEBUG=config:* or DEBUG=*)
- Writes to stderr with colors/time-diffs in TTY mode
- Also written to the file logger for production troubleshooting

Remove the now-unnecessary SetDebug function; callers can use the
standard DEBUG env var to enable config debug output.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@github-actions github-actions bot added automation enhancement New feature or request labels Apr 8, 2026
@lpcox lpcox marked this pull request as ready for review April 11, 2026 20:04
Copilot AI review requested due to automatic review settings April 11, 2026 20:04
@lpcox lpcox merged commit aa53adc into main Apr 11, 2026
4 checks passed
@lpcox lpcox deleted the log/config-core-debug-logger-aca44b5a3cdcafd8 branch April 11, 2026 20:05
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Migrates the config package’s debug logging in internal/config/config_core.go from a legacy log.New(io.Discard, ...) approach to the repo’s standard internal/logger debug logger, so config debug output can be controlled via DEBUG patterns.

Changes:

  • Remove legacy logConfig initialization and SetDebug toggling.
  • Introduce logConfig as a logger.New(...) instance controlled by DEBUG.
Show a summary per file
File Description
internal/config/config_core.go Replaces legacy stdlib logger + SetDebug with project debug logger instance.

Copilot's findings

Tip

Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

  • Files reviewed: 1/1 changed files
  • Comments generated: 1

Comment on lines +393 to +395
// logConfig is the debug logger for the config package.
// Enable with DEBUG=config:* or DEBUG=*.
var logConfig = logger.New("config:config")
Copy link

Copilot AI Apr 11, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

logConfig is initialized at package init via logger.New(...), which computes the enabled state once at construction time. Since the CLI sets DEBUG at runtime in internal/cmd/root.go (for -vv/-vvv), this logger will stay disabled even after DEBUG is set, so these config debug logs still won’t appear when users enable verbosity flags. Consider constructing the logger lazily after DEBUG is finalized (e.g., create it inside the load functions or behind a sync.Once getter), or adjust the logger implementation to re-evaluate DEBUG on each call.

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

automation enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants