Skip to content

Commit 8d1a49e

Browse files
authored
[log] Add debug logging to dockerutil/env.go (#1522)
## Changes Adds a debug logger to `internal/dockerutil/env.go` to trace Docker `-e` flag environment variable expansion. ### What was added - **Logger declaration**: `var logDockerutil = logger.New("dockerutil:env")` following the project's `pkg:filename` naming convention - **4 debug logging calls** in `ExpandEnvArgs`: 1. Function entry log with input arg count 2. Per-env-var log when a variable is successfully found and expanded 3. Per-env-var log when a referenced variable is **not found** in the process environment (key debugging signal) 4. Completion log with output arg count ### Why this is useful `ExpandEnvArgs` is called when building Docker command arguments, converting passthrough `-e VAR_NAME` flags to `-e VAR_NAME=value`. Without logging, there's no visibility into: - Which env vars are being passed through to Docker containers - Which env vars are missing from the gateway process environment (a common misconfiguration) - Whether the expansion produced the expected number of args The "not found" log is especially valuable - it highlights env vars that are referenced in config but not set in the environment, which is a common source of unexpected Docker container behavior. ### Debug usage ```bash # Enable dockerutil debug logging DEBUG=dockerutil:* ./awmg --config config.toml # Example output [dockerutil:env] Expanding env args: input_count=8 [dockerutil:env] Expanding env var: name=GITHUB_PERSONAL_ACCESS_TOKEN [dockerutil:env] Env var not found in process environment: name=MISSING_VAR [dockerutil:env] Env args expansion complete: output_count=9 ``` ### Quality checklist - [x] Exactly 1 file modified - [x] No test files modified - [x] Logger declaration added following `pkg:filename` convention (`dockerutil:env`) - [x] Logger arguments don't compute anything or cause side effects (only passes existing variable names/counts) - [x] Logging messages are meaningful and helpful - [x] No duplicate logging with existing logs - [x] Import statements properly formatted with stdlib imports before external imports > Generated by [Go Logger Enhancement](https://github.com/github/gh-aw-mcpg/actions/runs/22523661602) <!-- gh-aw-agentic-workflow: Go Logger Enhancement, engine: copilot, id: 22523661602, workflow_id: go-logger, run: https://github.com/github/gh-aw-mcpg/actions/runs/22523661602 --> <!-- gh-aw-workflow-id: go-logger -->
2 parents ca30b33 + 8cda897 commit 8d1a49e

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

internal/dockerutil/env.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,16 @@ import (
44
"fmt"
55
"os"
66
"strings"
7+
8+
"github.com/github/gh-aw-mcpg/internal/logger"
79
)
810

11+
var logDockerutil = logger.New("dockerutil:env")
12+
913
// ExpandEnvArgs expands Docker -e flags that reference environment variables
1014
// Converts "-e VAR_NAME" to "-e VAR_NAME=value" by reading from the process environment
1115
func ExpandEnvArgs(args []string) []string {
16+
logDockerutil.Printf("Expanding env args: input_count=%d", len(args))
1217
result := make([]string, 0, len(args))
1318
for i := 0; i < len(args); i++ {
1419
arg := args[i]
@@ -20,14 +25,17 @@ func ExpandEnvArgs(args []string) []string {
2025
if len(nextArg) > 0 && !strings.Contains(nextArg, "=") {
2126
// Look up the variable in the environment
2227
if value, exists := os.LookupEnv(nextArg); exists {
28+
logDockerutil.Printf("Expanding env var: name=%s", nextArg)
2329
result = append(result, "-e")
2430
result = append(result, fmt.Sprintf("%s=%s", nextArg, value))
2531
i++ // Skip the next arg since we processed it
2632
continue
2733
}
34+
logDockerutil.Printf("Env var not found in process environment: name=%s", nextArg)
2835
}
2936
}
3037
result = append(result, arg)
3138
}
39+
logDockerutil.Printf("Env args expansion complete: output_count=%d", len(result))
3240
return result
3341
}

0 commit comments

Comments
 (0)