on main help sign in
fix: structure logging
d896927Carlos Alexandro Becker
internal/cmd/root.go+3−3
@@ -85,14 +85,14 @@ to assist developers in writing, debugging, and understanding code directly from
85
85
86 app, err := app.New(ctx, conn, cfg)
86 app, err := app.New(ctx, conn, cfg)
87 if err != nil {
87 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)
89 return err
89 return err
90 }
90 }
91 defer app.Shutdown()
91 defer app.Shutdown()
92
92
93 prompt, err = maybePrependStdin(prompt)
93 prompt, err = maybePrependStdin(prompt)
94 if err != nil {
94 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)
96 return err
96 return err
97 }
97 }
98
98
@@ -114,7 +114,7 @@ to assist developers in writing, debugging, and understanding code directly from
114 go app.Subscribe(program)
114 go app.Subscribe(program)
115
115
116 if _, err := program.Run(); err != nil {
116 if _, err := program.Run(); err != nil {
117− slog.Error(fmt.Sprintf("TUI run error: %v", err))
117+ slog.Error("TUI run error", "error", err)
118 return fmt.Errorf("TUI error: %v", err)
118 return fmt.Errorf("TUI error: %v", err)
119 }
119 }
120 return nil
120 return nil
internal/llm/agent/agent.go+3−3
@@ -227,7 +227,7 @@ func (a *agent) Cancel(sessionID string) {
227 // Cancel regular requests
227 // Cancel regular requests
228 if cancelFunc, exists := a.activeRequests.LoadAndDelete(sessionID); exists {
228 if cancelFunc, exists := a.activeRequests.LoadAndDelete(sessionID); exists {
229 if cancel, ok := cancelFunc.(context.CancelFunc); ok {
229 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)
231 cancel()
231 cancel()
232 }
232 }
233 }
233 }
@@ -235,7 +235,7 @@ func (a *agent) Cancel(sessionID string) {
235 // Also check for summarize requests
235 // Also check for summarize requests
236 if cancelFunc, exists := a.activeRequests.LoadAndDelete(sessionID + "-summarize"); exists {
236 if cancelFunc, exists := a.activeRequests.LoadAndDelete(sessionID + "-summarize"); exists {
237 if cancel, ok := cancelFunc.(context.CancelFunc); ok {
237 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)
239 cancel()
239 cancel()
240 }
240 }
241 }
241 }
@@ -365,7 +365,7 @@ func (a *agent) processGeneration(ctx context.Context, sessionID, content string
365 })
365 })
366 titleErr := a.generateTitle(context.Background(), sessionID, content)
366 titleErr := a.generateTitle(context.Background(), sessionID, content)
367 if titleErr != nil && !errors.Is(titleErr, context.Canceled) && !errors.Is(titleErr, context.DeadlineExceeded) {
367 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)
369 }
369 }
370 }()
370 }()
371 }
371 }
internal/llm/provider/anthropic.go+2−2
@@ -248,7 +248,7 @@ func (a *anthropicClient) send(ctx context.Context, messages []message.Message,
248 return nil, retryErr
248 return nil, retryErr
249 }
249 }
250 if retry {
250 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)
252 select {
252 select {
253 case <-ctx.Done():
253 case <-ctx.Done():
254 return nil, ctx.Err()
254 return nil, ctx.Err()
@@ -401,7 +401,7 @@ func (a *anthropicClient) stream(ctx context.Context, messages []message.Message
401 return
401 return
402 }
402 }
403 if retry {
403 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)
405 select {
405 select {
406 case <-ctx.Done():
406 case <-ctx.Done():
407 // context cancelled
407 // context cancelled
internal/llm/provider/gemini.go+2−2
@@ -210,7 +210,7 @@ func (g *geminiClient) send(ctx context.Context, messages []message.Message, too
210 return nil, retryErr
210 return nil, retryErr
211 }
211 }
212 if retry {
212 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)
214 select {
214 select {
215 case <-ctx.Done():
215 case <-ctx.Done():
216 return nil, ctx.Err()
216 return nil, ctx.Err()
@@ -323,7 +323,7 @@ func (g *geminiClient) stream(ctx context.Context, messages []message.Message, t
323 return
323 return
324 }
324 }
325 if retry {
325 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)
327 select {
327 select {
328 case <-ctx.Done():
328 case <-ctx.Done():
329 if ctx.Err() != nil {
329 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
222 return nil, retryErr
222 return nil, retryErr
223 }
223 }
224 if retry {
224 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)
226 select {
226 select {
227 case <-ctx.Done():
227 case <-ctx.Done():
228 return nil, ctx.Err()
228 return nil, ctx.Err()
@@ -395,7 +395,7 @@ func (o *openaiClient) stream(ctx context.Context, messages []message.Message, t
395 return
395 return
396 }
396 }
397 if retry {
397 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)
399 select {
399 select {
400 case <-ctx.Done():
400 case <-ctx.Done():
401 // context cancelled
401 // context cancelled
internal/llm/tools/glob.go+1−1
@@ -146,7 +146,7 @@ func globFiles(pattern, searchPath string, limit int) ([]string, bool, error) {
146 if err == nil {
146 if err == nil {
147 return matches, len(matches) >= limit && limit > 0, nil
147 return matches, len(matches) >= limit && limit > 0, nil
148 }
148 }
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)
150 }
150 }
151
151
152 return fsext.GlobWithDoubleStar(pattern, searchPath, limit)
152 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
90 slog.Debug("BaseURI", "baseURI", u)
90 slog.Debug("BaseURI", "baseURI", u)
91 }
91 }
92 default:
92 default:
93− slog.Debug("GlobPattern", "unknown type", fmt.Sprintf("%T", v))
93+ slog.Debug("GlobPattern unknown type", "type", fmt.Sprintf("%T", v))
94 }
94 }
95
95
96 // Log WatchKind
96 // Log WatchKind
main.go+1−2
@@ -1,7 +1,6 @@
1package main
1package main
2
2
3import (
3import (
4− "fmt"
5 "log/slog"
4 "log/slog"
6 "net/http"
5 "net/http"
7 "os"
6 "os"
@@ -23,7 +22,7 @@ func main() {
23 go func() {
22 go func() {
24 slog.Info("Serving pprof at localhost:6060")
23 slog.Info("Serving pprof at localhost:6060")
25 if httpErr := http.ListenAndServe("localhost:6060", nil); httpErr != nil {
24 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)
27 }
26 }
28 }()
27 }()
29 }
28 }