Skip to content

Commit 3e52289

Browse files
authored
[log] Add debug logging to main.go (#914)
## Summary Enhanced `main.go` with debug logging to improve troubleshooting and development visibility. ## Changes Made Added 7 meaningful debug logging statements: - **Application lifecycle**: Log at application start and before executing root command - **Version string construction**: Log when building version string with metadata - **Version determination**: Log whether using ldflags version or defaulting to 'dev' - **Git commit tracking**: Log commit source (ldflags vs build info) and extraction process - **Build metadata**: Log commit hash found in build info ## Technical Details - Added logger import: `"github.com/github/gh-aw-mcpg/internal/logger"` - Added logger declaration: `var log = logger.New("main:main")` - All logging follows project guidelines from AGENTS.md: - Uses correct naming convention (`main:main`) - No side effects in log arguments - Meaningful messages for debugging - Focused on entry points and control flow ## Testing To see the new debug logs in action: ``````bash DEBUG=main:* ./awmg --version `````` This will show the version string construction process with all intermediate steps. ## Quality Checklist - ✅ Exactly 1 file modified (focused, single-file PR) - ✅ No test files modified - ✅ Logger naming follows `pkg:filename` convention - ✅ Logger arguments don't compute anything or cause side effects - ✅ Logging messages are meaningful and helpful - ✅ No duplicate logging with existing logs - ✅ Import statements properly formatted > AI generated by [Go Logger Enhancement](https://github.com/github/gh-aw-mcpg/actions/runs/21946284845) <!-- gh-aw-workflow-id: go-logger -->
2 parents 1041860 + 0c91a3a commit 3e52289

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

main.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,23 @@ import (
66
"strings"
77

88
"github.com/github/gh-aw-mcpg/internal/cmd"
9+
"github.com/github/gh-aw-mcpg/internal/logger"
910
)
1011

12+
var log = logger.New("main:main")
13+
1114
func main() {
15+
log.Print("Starting MCP Gateway application")
16+
1217
// Build version string with metadata
1318
versionStr := buildVersionString()
19+
log.Printf("Built version string: %s", versionStr)
1420

1521
// Set the version for the CLI
1622
cmd.SetVersion(versionStr)
1723

1824
// Execute the root command
25+
log.Print("Executing root command")
1926
cmd.Execute()
2027
}
2128

@@ -25,26 +32,32 @@ const (
2532

2633
// buildVersionString constructs a detailed version string with build metadata
2734
func buildVersionString() string {
35+
log.Print("Building version string from build metadata")
2836
var parts []string
2937

3038
// Add main version
3139
if Version != "" {
40+
log.Printf("Using version from ldflags: %s", Version)
3241
parts = append(parts, Version)
3342
} else {
43+
log.Print("No version set, using 'dev'")
3444
parts = append(parts, "dev")
3545
}
3646

3747
// Add git commit if available
3848
if GitCommit != "" {
49+
log.Printf("Using git commit from ldflags: %s", GitCommit)
3950
parts = append(parts, fmt.Sprintf("commit: %s", GitCommit))
4051
} else if buildInfo, ok := debug.ReadBuildInfo(); ok {
52+
log.Print("Extracting commit hash from build info")
4153
// Try to extract commit from build info if not set via ldflags
4254
for _, setting := range buildInfo.Settings {
4355
if setting.Key == "vcs.revision" {
4456
commitHash := setting.Value
4557
if len(commitHash) > shortHashLength {
4658
commitHash = commitHash[:shortHashLength] // Short hash
4759
}
60+
log.Printf("Found commit hash in build info: %s", commitHash)
4861
parts = append(parts, fmt.Sprintf("commit: %s", commitHash))
4962
break
5063
}

0 commit comments

Comments
 (0)