on main help sign in
fix: structure logging
commitd896927841ea74597e2bab5b41463b41676c2201 authorCarlos Alexandro Becker <caarlos0@users.noreply.github.com> dateWed 23 Jul 2025, 16:04 (1 year ago) parentda127ca
8 files changed+15−16
internal/cmd/root.go+3−3 internal/llm/agent/agent.go+3−3 internal/llm/provider/anthropic.go+2−2 internal/llm/provider/gemini.go+2−2 internal/llm/provider/openai.go+2−2 internal/llm/tools/glob.go+1−1 internal/lsp/watcher/watcher.go+1−1 main.go+1−2
internal/cmd/root.go+3−3
@@ -85,14 +85,14 @@ to assist developers in writing, debugging, and understanding code directly from
8585
8686 app, err := app.New(ctx, conn, cfg)
8787 if err != nil {
88− slog.Error(fmt.Sprintf("Failed to create app instance: %v", err))
88+ slog.Error("Failed to create app instance", "error", err)
8989 return err
9090 }
9191 defer app.Shutdown()
9292
9393 prompt, err = maybePrependStdin(prompt)
9494 if err != nil {
95− slog.Error(fmt.Sprintf("Failed to read from stdin: %v", err))
95+ slog.Error("Failed to read from stdin", "error", err)
9696 return err
9797 }
9898
@@ -114,7 +114,7 @@ to assist developers in writing, debugging, and understanding code directly from
114114 go app.Subscribe(program)
115115
116116 if _, err := program.Run(); err != nil {
117− slog.Error(fmt.Sprintf("TUI run error: %v", err))
117+ slog.Error("TUI run error", "error", err)
118118 return fmt.Errorf("TUI error: %v", err)
119119 }
120120 return nil
internal/llm/agent/agent.go+3−3
@@ -227,7 +227,7 @@ func (a *agent) Cancel(sessionID string) {
227227 // Cancel regular requests
228228 if cancelFunc, exists := a.activeRequests.LoadAndDelete(sessionID); exists {
229229 if cancel, ok := cancelFunc.(context.CancelFunc); ok {
230− slog.Info(fmt.Sprintf("Request cancellation initiated for session: %s", sessionID))
230+ slog.Info("Request cancellation initiated", "session_id", sessionID)
231231 cancel()
232232 }
233233 }
@@ -235,7 +235,7 @@ func (a *agent) Cancel(sessionID string) {
235235 // Also check for summarize requests
236236 if cancelFunc, exists := a.activeRequests.LoadAndDelete(sessionID + "-summarize"); exists {
237237 if cancel, ok := cancelFunc.(context.CancelFunc); ok {
238− slog.Info(fmt.Sprintf("Summarize cancellation initiated for session: %s", sessionID))
238+ slog.Info("Summarize cancellation initiated", "session_id", sessionID)
239239 cancel()
240240 }
241241 }
@@ -365,7 +365,7 @@ func (a *agent) processGeneration(ctx context.Context, sessionID, content string
365365 })
366366 titleErr := a.generateTitle(context.Background(), sessionID, content)
367367 if titleErr != nil && !errors.Is(titleErr, context.Canceled) && !errors.Is(titleErr, context.DeadlineExceeded) {
368− slog.Error(fmt.Sprintf("failed to generate title: %v", titleErr))
368+ slog.Error("failed to generate title", "error", titleErr)
369369 }
370370 }()
371371 }
internal/llm/provider/anthropic.go+2−2
@@ -248,7 +248,7 @@ func (a *anthropicClient) send(ctx context.Context, messages []message.Message,
248248 return nil, retryErr
249249 }
250250 if retry {
251− slog.Warn(fmt.Sprintf("Retrying due to rate limit... attempt %d of %d", attempts, maxRetries))
251+ slog.Warn("Retrying due to rate limit", "attempt", attempts, "max_retries", maxRetries)
252252 select {
253253 case <-ctx.Done():
254254 return nil, ctx.Err()
@@ -401,7 +401,7 @@ func (a *anthropicClient) stream(ctx context.Context, messages []message.Message
401401 return
402402 }
403403 if retry {
404− slog.Warn(fmt.Sprintf("Retrying due to rate limit... attempt %d of %d", attempts, maxRetries))
404+ slog.Warn("Retrying due to rate limit", "attempt", attempts, "max_retries", maxRetries)
405405 select {
406406 case <-ctx.Done():
407407 // context cancelled
internal/llm/provider/gemini.go+2−2
@@ -210,7 +210,7 @@ func (g *geminiClient) send(ctx context.Context, messages []message.Message, too
210210 return nil, retryErr
211211 }
212212 if retry {
213− slog.Warn(fmt.Sprintf("Retrying due to rate limit... attempt %d of %d", attempts, maxRetries))
213+ slog.Warn("Retrying due to rate limit", "attempt", attempts, "max_retries", maxRetries)
214214 select {
215215 case <-ctx.Done():
216216 return nil, ctx.Err()
@@ -323,7 +323,7 @@ func (g *geminiClient) stream(ctx context.Context, messages []message.Message, t
323323 return
324324 }
325325 if retry {
326− slog.Warn(fmt.Sprintf("Retrying due to rate limit... attempt %d of %d", attempts, maxRetries))
326+ slog.Warn("Retrying due to rate limit", "attempt", attempts, "max_retries", maxRetries)
327327 select {
328328 case <-ctx.Done():
329329 if ctx.Err() != nil {
internal/llm/provider/openai.go+2−2
@@ -222,7 +222,7 @@ func (o *openaiClient) send(ctx context.Context, messages []message.Message, too
222222 return nil, retryErr
223223 }
224224 if retry {
225− slog.Warn(fmt.Sprintf("Retrying due to rate limit... attempt %d of %d", attempts, maxRetries))
225+ slog.Warn("Retrying due to rate limit", "attempt", attempts, "max_retries", maxRetries)
226226 select {
227227 case <-ctx.Done():
228228 return nil, ctx.Err()
@@ -395,7 +395,7 @@ func (o *openaiClient) stream(ctx context.Context, messages []message.Message, t
395395 return
396396 }
397397 if retry {
398− slog.Warn(fmt.Sprintf("Retrying due to rate limit... attempt %d of %d", attempts, maxRetries))
398+ slog.Warn("Retrying due to rate limit", "attempt", attempts, "max_retries", maxRetries)
399399 select {
400400 case <-ctx.Done():
401401 // context cancelled
internal/llm/tools/glob.go+1−1
@@ -146,7 +146,7 @@ func globFiles(pattern, searchPath string, limit int) ([]string, bool, error) {
146146 if err == nil {
147147 return matches, len(matches) >= limit && limit > 0, nil
148148 }
149− slog.Warn(fmt.Sprintf("Ripgrep execution failed: %v. Falling back to doublestar.", err))
149+ slog.Warn("Ripgrep execution failed, falling back to doublestar", "error", err)
150150 }
151151
152152 return fsext.GlobWithDoubleStar(pattern, searchPath, limit)
internal/lsp/watcher/watcher.go+1−1
@@ -90,7 +90,7 @@ func (w *WorkspaceWatcher) AddRegistrations(ctx context.Context, id string, watc
9090 slog.Debug("BaseURI", "baseURI", u)
9191 }
9292 default:
93− slog.Debug("GlobPattern", "unknown type", fmt.Sprintf("%T", v))
93+ slog.Debug("GlobPattern unknown type", "type", fmt.Sprintf("%T", v))
9494 }
9595
9696 // Log WatchKind
main.go+1−2
@@ -1,7 +1,6 @@
11package main
22
33import (
4− "fmt"
54 "log/slog"
65 "net/http"
76 "os"
@@ -23,7 +22,7 @@ func main() {
2322 go func() {
2423 slog.Info("Serving pprof at localhost:6060")
2524 if httpErr := http.ListenAndServe("localhost:6060", nil); httpErr != nil {
26− slog.Error(fmt.Sprintf("Failed to pprof listen: %v", httpErr))
25+ slog.Error("Failed to pprof listen", "error", httpErr)
2726 }
2827 }()
2928 }