From 653cb8117da3ffd80954a84a75b56fa44868d5a8 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Thu, 25 Dec 2025 06:31:17 +0000 Subject: [PATCH] Add debug logging to CLI utility and configuration files MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Enhanced 5 Go files with debug logging following project guidelines: - pkg/cli/ci.go: CI environment detection logging - pkg/cli/github.go: GitHub host resolution logging - pkg/cli/compile_config.go: Validation error sanitization logging - pkg/cli/logs_display.go: Logs display metrics aggregation logging - pkg/cli/logs_command.go: Logs command parameter validation logging All loggers follow the pkg:filename naming convention and avoid side effects in log arguments. Session 28 of the go-logger enhancement initiative. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Sonnet 4.5 --- pkg/cli/ci.go | 10 +++++++++- pkg/cli/compile_config.go | 13 +++++++++++++ pkg/cli/github.go | 7 +++++++ pkg/cli/logs_command.go | 14 ++++++++++++++ pkg/cli/logs_display.go | 8 ++++++++ 5 files changed, 51 insertions(+), 1 deletion(-) diff --git a/pkg/cli/ci.go b/pkg/cli/ci.go index 56a748ccad..dcb940c258 100644 --- a/pkg/cli/ci.go +++ b/pkg/cli/ci.go @@ -1,6 +1,12 @@ package cli -import "os" +import ( + "os" + + "github.com/githubnext/gh-aw/pkg/logger" +) + +var ciLog = logger.New("cli:ci") // IsRunningInCI checks if we're running in a CI environment func IsRunningInCI() bool { @@ -13,8 +19,10 @@ func IsRunningInCI() bool { for _, v := range ciVars { if os.Getenv(v) != "" { + ciLog.Printf("CI environment detected via %s", v) return true } } + ciLog.Print("No CI environment detected") return false } diff --git a/pkg/cli/compile_config.go b/pkg/cli/compile_config.go index 94e7c7de2e..7f83d70590 100644 --- a/pkg/cli/compile_config.go +++ b/pkg/cli/compile_config.go @@ -2,8 +2,12 @@ package cli import ( "regexp" + + "github.com/githubnext/gh-aw/pkg/logger" ) +var compileConfigLog = logger.New("cli:compile_config") + // CompileConfig holds configuration options for compiling workflows type CompileConfig struct { MarkdownFiles []string // Files to compile (empty for all files) @@ -105,18 +109,25 @@ func sanitizeErrorMessage(message string) string { return message } + compileConfigLog.Printf("Sanitizing error message: length=%d", len(message)) + // Redact uppercase snake_case patterns (e.g., MY_SECRET_KEY, API_TOKEN) sanitized := secretNamePattern.ReplaceAllStringFunc(message, func(match string) string { // Don't redact common workflow keywords if commonWorkflowKeywords[match] { return match } + compileConfigLog.Printf("Redacted snake_case secret pattern: %s", match) return "[REDACTED]" }) // Redact PascalCase patterns ending with security suffixes (e.g., GitHubToken, ApiKey) sanitized = pascalCaseSecretPattern.ReplaceAllString(sanitized, "[REDACTED]") + if sanitized != message { + compileConfigLog.Print("Error message sanitization applied redactions") + } + return sanitized } @@ -129,6 +140,8 @@ func sanitizeValidationResults(results []ValidationResult) []ValidationResult { return nil } + compileConfigLog.Printf("Sanitizing validation results: workflow_count=%d", len(results)) + sanitized := make([]ValidationResult, len(results)) for i, result := range results { sanitized[i] = ValidationResult{ diff --git a/pkg/cli/github.go b/pkg/cli/github.go index 8b2bac1a19..2199d70e39 100644 --- a/pkg/cli/github.go +++ b/pkg/cli/github.go @@ -3,8 +3,12 @@ package cli import ( "os" "strings" + + "github.com/githubnext/gh-aw/pkg/logger" ) +var githubLog = logger.New("cli:github") + // getGitHubHost returns the GitHub host URL from environment variables. // It checks GITHUB_SERVER_URL first (GitHub Actions standard), // then falls back to GH_HOST (gh CLI standard), @@ -16,6 +20,9 @@ func getGitHubHost() string { } if host == "" { host = "https://github.com" + githubLog.Print("Using default GitHub host: https://github.com") + } else { + githubLog.Printf("Resolved GitHub host: %s", host) } // Remove trailing slash for consistency diff --git a/pkg/cli/logs_command.go b/pkg/cli/logs_command.go index 8cbe706190..50b22a7b2c 100644 --- a/pkg/cli/logs_command.go +++ b/pkg/cli/logs_command.go @@ -16,10 +16,13 @@ import ( "github.com/githubnext/gh-aw/pkg/console" "github.com/githubnext/gh-aw/pkg/constants" + "github.com/githubnext/gh-aw/pkg/logger" "github.com/githubnext/gh-aw/pkg/workflow" "github.com/spf13/cobra" ) +var logsCommandLog = logger.New("cli:logs_command") + // NewLogsCommand creates the logs command func NewLogsCommand() *cobra.Command { logsCmd := &cobra.Command{ @@ -102,8 +105,12 @@ Examples: ` + constants.CLIExtensionPrefix + ` logs --parse --json # Generate both Markdown and JSON ` + constants.CLIExtensionPrefix + ` logs weekly-research --repo owner/repo # Download logs from specific repository`, RunE: func(cmd *cobra.Command, args []string) error { + logsCommandLog.Printf("Starting logs command: args=%d", len(args)) + var workflowName string if len(args) > 0 && args[0] != "" { + logsCommandLog.Printf("Resolving workflow name from argument: %s", args[0]) + // Convert workflow ID to GitHub Actions workflow name // First try to resolve as a workflow ID resolvedName, err := workflow.ResolveWorkflowName(args[0]) @@ -161,22 +168,27 @@ Examples: // Resolve relative dates to absolute dates for GitHub CLI now := time.Now() if startDate != "" { + logsCommandLog.Printf("Resolving start date: %s", startDate) resolvedStartDate, err := workflow.ResolveRelativeDate(startDate, now) if err != nil { return fmt.Errorf("invalid start-date format '%s': %v", startDate, err) } startDate = resolvedStartDate + logsCommandLog.Printf("Resolved start date to: %s", startDate) } if endDate != "" { + logsCommandLog.Printf("Resolving end date: %s", endDate) resolvedEndDate, err := workflow.ResolveRelativeDate(endDate, now) if err != nil { return fmt.Errorf("invalid end-date format '%s': %v", endDate, err) } endDate = resolvedEndDate + logsCommandLog.Printf("Resolved end date to: %s", endDate) } // Validate engine parameter using the engine registry if engine != "" { + logsCommandLog.Printf("Validating engine parameter: %s", engine) registry := workflow.GetGlobalEngineRegistry() if !registry.IsValidEngine(engine) { supportedEngines := registry.GetSupportedEngines() @@ -184,6 +196,8 @@ Examples: } } + logsCommandLog.Printf("Executing logs download: workflow=%s, count=%d, engine=%s", workflowName, count, engine) + return DownloadWorkflowLogs(workflowName, count, startDate, endDate, outputDir, engine, ref, beforeRunID, afterRunID, repoOverride, verbose, toolGraph, noStaged, firewallOnly, noFirewall, parse, jsonOutput, timeout, campaignOnly, summaryFile) }, } diff --git a/pkg/cli/logs_display.go b/pkg/cli/logs_display.go index b591739321..7935e24ee9 100644 --- a/pkg/cli/logs_display.go +++ b/pkg/cli/logs_display.go @@ -15,15 +15,21 @@ import ( "time" "github.com/githubnext/gh-aw/pkg/console" + "github.com/githubnext/gh-aw/pkg/logger" "github.com/githubnext/gh-aw/pkg/timeutil" ) +var logsDisplayLog = logger.New("cli:logs_display") + // displayLogsOverview displays a summary table of workflow runs and metrics func displayLogsOverview(processedRuns []ProcessedRun, verbose bool) { if len(processedRuns) == 0 { + logsDisplayLog.Print("No processed runs to display") return } + logsDisplayLog.Printf("Displaying logs overview: runs=%d, verbose=%v", len(processedRuns), verbose) + // Prepare table data headers := []string{"Run ID", "Workflow", "Status", "Duration", "Tokens", "Cost ($)", "Turns", "Errors", "Warnings", "Missing", "Noops", "Created", "Logs Path"} var rows [][]string @@ -176,5 +182,7 @@ func displayLogsOverview(processedRuns []ProcessedRun, verbose bool) { TotalRow: totalRow, } + logsDisplayLog.Printf("Rendering table: total_tokens=%d, total_cost=%.3f, total_duration=%s", totalTokens, totalCost, totalDuration) + fmt.Print(console.RenderTable(tableConfig)) }