Skip to content

Commit 0d4e760

Browse files
authored
[log] Add debug logging to container detection in sys/container.go (#2598)
## Summary Adds a package-level debug logger (`logSys`) and 4 meaningful debug log calls to `internal/sys/container.go`, following the project's `pkg:filename` naming convention from AGENTS.md. ## Changes **File modified:** `internal/sys/container.go` ### What was added 1. Import for `github.com/github/gh-aw-mcpg/internal/logger` 2. Package-level logger variable: `var logSys = logger.New("sys:container")` 3. Debug log at function entry: `"Detecting container environment"` 4. Detection method trace logs for each of the 3 detection paths: - `"Container detected via /.dockerenv"` (Method 1) - `"Container detected via /proc/1/cgroup"` (Method 2) - `"Container detected via RUNNING_IN_CONTAINER env var"` (Method 3) 5. Fallback log: `"No container indicators found, running on host"` ## Why this is useful `IsRunningInContainer()` is a critical detection function used to determine execution context and control security behavior (e.g., whether direct command execution is permitted). When troubleshooting container detection issues, developers had no visibility into which detection method triggered (or why detection failed). With this change, running `DEBUG=sys:* ./awmg --config config.toml` reveals exactly which method fires. ## Quality checklist - [x] Exactly 1 file modified - [x] No test files modified - [x] Logger declaration added following `pkg:filename` convention (`sys:container`) - [x] Log arguments are all string literals (no side effects) - [x] Messages are meaningful and actionable for debugging - [x] No duplicate logging with existing logs - [x] Import statements properly formatted - [x] Naming follows project convention (`logSys` matches `logConn`, `logSchema`, etc.) > Generated by [Go Logger Enhancement](https://github.com/github/gh-aw-mcpg/actions/runs/23612565368) · [◷](https://github.com/search?q=repo%3Agithub%2Fgh-aw-mcpg+%22gh-aw-workflow-id%3A+go-logger%22&type=pullrequests) <!-- gh-aw-agentic-workflow: Go Logger Enhancement, engine: copilot, model: auto, id: 23612565368, workflow_id: go-logger, run: https://github.com/github/gh-aw-mcpg/actions/runs/23612565368 --> <!-- gh-aw-workflow-id: go-logger -->
2 parents d6573c0 + 26151ec commit 0d4e760

1 file changed

Lines changed: 10 additions & 0 deletions

File tree

internal/sys/container.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,19 @@ package sys
33
import (
44
"os"
55
"strings"
6+
7+
"github.com/github/gh-aw-mcpg/internal/logger"
68
)
79

10+
var logSys = logger.New("sys:container")
11+
812
// IsRunningInContainer detects if the current process is running inside a container.
913
func IsRunningInContainer() bool {
14+
logSys.Print("Detecting container environment")
15+
1016
// Method 1: Check for /.dockerenv file (Docker-specific)
1117
if _, err := os.Stat("/.dockerenv"); err == nil {
18+
logSys.Print("Container detected via /.dockerenv")
1219
return true
1320
}
1421

@@ -20,14 +27,17 @@ func IsRunningInContainer() bool {
2027
strings.Contains(content, "containerd") ||
2128
strings.Contains(content, "kubepods") ||
2229
strings.Contains(content, "lxc") {
30+
logSys.Print("Container detected via /proc/1/cgroup")
2331
return true
2432
}
2533
}
2634

2735
// Method 3: Check environment variable (set by Dockerfile)
2836
if os.Getenv("RUNNING_IN_CONTAINER") == "true" {
37+
logSys.Print("Container detected via RUNNING_IN_CONTAINER env var")
2938
return true
3039
}
3140

41+
logSys.Print("No container indicators found, running on host")
3242
return false
3343
}

0 commit comments

Comments
 (0)