-
Notifications
You must be signed in to change notification settings - Fork 0
refactor: replace fmt.Print* with log/slog for structured logging #14
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,7 @@ | ||
| package main | ||
|
|
||
| import ( | ||
| "fmt" | ||
| "log/slog" | ||
| "os" | ||
|
|
||
| "github.com/go-errors/errors" | ||
|
|
@@ -41,7 +41,7 @@ files (raw.log, summary.txt, errors.txt) in a local directory for inspection.`, | |
| func runDebugWorkspace(cmd *cobra.Command, args []string) error { | ||
| logFile := args[0] | ||
|
|
||
| fmt.Fprintf(os.Stderr, "Reading logs...\n") | ||
| slog.Info("Reading logs...") | ||
| lines, err := readLines(logFile) | ||
| if err != nil { | ||
| return errors.Errorf("read log file: %w", err) | ||
|
|
@@ -55,7 +55,7 @@ func runDebugWorkspace(cmd *cobra.Command, args []string) error { | |
| for i, m := range merged { | ||
| mergedLines[i] = m.Content | ||
| } | ||
| fmt.Fprintf(os.Stderr, "Read %d lines, merged into %d entries\n", len(lines), len(mergedLines)) | ||
| slog.Info("Read lines", "lines", len(lines), "merged_entries", len(mergedLines)) | ||
|
|
||
| outDir := debugWorkspaceOutput | ||
| if outDir == "" { | ||
|
|
@@ -74,7 +74,7 @@ func runDebugWorkspace(cmd *cobra.Command, args []string) error { | |
| return errors.Errorf("drain parser: %w", err) | ||
| } | ||
|
|
||
| fmt.Fprintf(os.Stderr, "Parsing %d entries...\n", len(mergedLines)) | ||
| slog.Info("Parsing entries", "count", len(mergedLines)) | ||
| if err := drainParser.Feed(mergedLines); err != nil { | ||
| return errors.Errorf("drain feed: %w", err) | ||
| } | ||
|
|
@@ -87,8 +87,7 @@ func runDebugWorkspace(cmd *cobra.Command, args []string) error { | |
| return errors.Errorf("build workspace: %w", err) | ||
| } | ||
|
|
||
| fmt.Fprintf(os.Stderr, "Workspace created at: %s\n", outDir) | ||
| fmt.Println(outDir) | ||
| slog.Info("Workspace created", "dir", outDir) | ||
STRRL marked this conversation as resolved.
Show resolved
Hide resolved
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
In Useful? React with 👍 / 👎. |
||
| return nil | ||
| } | ||
|
|
||
|
|
@@ -130,12 +129,12 @@ func runDebugRun(cmd *cobra.Command, args []string) error { | |
| Model: debugRunModel, | ||
| } | ||
|
|
||
| fmt.Fprintf(os.Stderr, "Running agent on workspace: %s\n", workDir) | ||
| slog.Info("Running agent on workspace", "dir", workDir) | ||
| result, err := analyzer.RunAgent(cmd.Context(), config, workDir, question) | ||
| if err != nil { | ||
| return err | ||
| } | ||
|
|
||
| fmt.Println(result) | ||
| slog.Info(result) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Useful? React with 👍 / 👎. |
||
| return nil | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,7 @@ | ||
| package main | ||
|
|
||
| import ( | ||
| "fmt" | ||
| "log/slog" | ||
|
|
||
| "github.com/go-errors/errors" | ||
| "github.com/spf13/cobra" | ||
|
|
@@ -45,8 +45,6 @@ func runTemplates(cmd *cobra.Command, _ []string) error { | |
| } | ||
|
|
||
| if hasLabels { | ||
| fmt.Printf("%-12s %-6s %-22s %-6s %s\n", "ID", "TYPE", "SEMANTIC_ID", "COUNT", "DESCRIPTION") | ||
| fmt.Println("------------ ------ ---------------------- ------ ----------------------------------------") | ||
| for _, ts := range summaries { | ||
| semanticID := ts.SemanticID | ||
| if semanticID == "" { | ||
|
|
@@ -60,17 +58,26 @@ func runTemplates(cmd *cobra.Command, _ []string) error { | |
| if pType == "" { | ||
| pType = "-" | ||
| } | ||
| fmt.Printf("%-12s %-6s %-22s %-6d %s\n", ts.PatternUUIDString, pType, semanticID, ts.Count, desc) | ||
| slog.Info("template", | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The Useful? React with 👍 / 👎. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
The Useful? React with 👍 / 👎. |
||
| "id", ts.PatternUUIDString, | ||
| "type", pType, | ||
| "semantic_id", semanticID, | ||
| "count", ts.Count, | ||
| "description", desc, | ||
| ) | ||
| } | ||
| } else { | ||
| fmt.Printf("%-12s %-6s %-6s %s\n", "ID", "TYPE", "COUNT", "PATTERN") | ||
| fmt.Println("------------ ------ ------ ----------------------------------------") | ||
| for _, ts := range summaries { | ||
| pType := ts.PatternType | ||
| if pType == "" { | ||
| pType = "-" | ||
| } | ||
| fmt.Printf("%-12s %-6s %-6d %s\n", ts.PatternUUIDString, pType, ts.Count, ts.Pattern) | ||
| slog.Info("template", | ||
| "id", ts.PatternUUIDString, | ||
| "type", pType, | ||
| "count", ts.Count, | ||
| "pattern", ts.Pattern, | ||
| ) | ||
| } | ||
| } | ||
| return nil | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
analyze's primary payload is the model's final answer, but this now goes throughslog.Info, which uses the default logger and writes via thelogpackage to stderr by default; this breaks scripting/piping (lapp analyze ... > answer.txtcaptures nothing) and also prefixes the response with log metadata instead of returning raw analysis text.Useful? React with 👍 / 👎.