diff --git a/db/activity_outbox.go b/db/activity_outbox.go index b49f234f6..d43fe878d 100644 --- a/db/activity_outbox.go +++ b/db/activity_outbox.go @@ -3,7 +3,7 @@ package db import ( "encoding/json" "fmt" - "log" + "log/slog" ) // activityOutboxMaxAttempts is how many times a row may fail AppendActivity @@ -94,7 +94,7 @@ func (s *ExplorationStore) FlushActivityOutbox() (int, error) { _ = tx.Rollback() next := it.attempts + 1 if next >= activityOutboxMaxAttempts { - log.Printf("[activity] outbox %d for exploration %d dropped after %d attempts: %v", it.id, s.expID, next, err) + slog.Error("[activity] outbox entry dropped", "outbox_id", it.id, "exploration_id", s.expID, "attempts", next, "err", err) if _, delErr := s.db.Exec(`DELETE FROM activity_outbox WHERE id=$1`, it.id); delErr != nil { return stored, delErr } diff --git a/db/companies.go b/db/companies.go index ad5d23953..2020f413d 100644 --- a/db/companies.go +++ b/db/companies.go @@ -4,7 +4,7 @@ import ( "database/sql" "errors" "fmt" - "log" + "log/slog" "net" "strings" "unicode/utf8" @@ -583,7 +583,7 @@ const malformedIPAssetsSampled = 5 // per-request response (company deletion, scopesentry sync, agent asset writes). func logAttributionWarning(warning string) { if warning != "" { - log.Printf("[assets] %s", warning) + slog.Warn("[assets] " + warning) } } diff --git a/db/notification.go b/db/notification.go index da150b853..3c1a6787d 100644 --- a/db/notification.go +++ b/db/notification.go @@ -6,7 +6,7 @@ import ( "encoding/json" "errors" "fmt" - "log" + "log/slog" "strings" "time" @@ -247,19 +247,19 @@ func (d *DB) DeleteNotificationChannel(ctx context.Context, id int64) error { func RecordNotificationEventTx(ctx context.Context, tx *sql.Tx, kind string, findingID int64, snap notify.Snapshot) bool { raw, err := json.Marshal(snap) if err != nil { - log.Printf("[notify] failed to serialize delivery event finding=%d: %v", findingID, err) + slog.Error("[notify] failed to serialize delivery event", "finding", findingID, "err", err) return false } if _, err := tx.ExecContext(ctx, `SAVEPOINT notify_event`); err != nil { - log.Printf("[notify] failed to create savepoint finding=%d: %v", findingID, err) + slog.Error("[notify] failed to create savepoint", "finding", findingID, "err", err) return false } if _, err := tx.ExecContext(ctx, `INSERT INTO notification_events(kind,finding_id,snapshot) VALUES($1,$2,$3)`, kind, findingID, string(raw)); err != nil { - log.Printf("[notify] failed to write delivery event finding=%d (finding record unaffected): %v", findingID, err) + slog.Error("[notify] failed to write delivery event (finding record unaffected)", "finding", findingID, "err", err) // Roll back to the savepoint, rescuing the transaction from the aborted state. if _, rbErr := tx.ExecContext(ctx, `ROLLBACK TO SAVEPOINT notify_event`); rbErr != nil { - log.Printf("[notify] failed to roll back to savepoint finding=%d: %v", findingID, rbErr) + slog.Error("[notify] failed to roll back to savepoint", "finding", findingID, "err", rbErr) } return false } diff --git a/db/secrets.go b/db/secrets.go index 2a47e58a7..4db88b274 100644 --- a/db/secrets.go +++ b/db/secrets.go @@ -14,7 +14,7 @@ import ( "encoding/json" "errors" "fmt" - "log" + "log/slog" "os" "path/filepath" "strings" @@ -306,7 +306,7 @@ func (d *DB) InitSecrets(keyDir string) error { if err != nil { return err } - log.Printf("[secrets] at-rest encryption ready; backfill encrypted %d plaintext value(s)", n) + slog.Info("[secrets] at-rest encryption ready", "backfilled_plaintext_values", n) activeSecretBox.Store(box) sub := deriveSubKey(key, trafficTraceDomain) trafficTraceKey.Store(&sub) @@ -362,7 +362,7 @@ func loadSecretKey(ctx context.Context, conn *sql.Conn, keyDir string) ([]byte, _ = os.Remove(path) return nil, fmt.Errorf("write secret key: %w", err) } - log.Printf("[secrets] new secret key written to %s", path) + slog.Info("[secrets] new secret key written", "path", path) return key, nil } diff --git a/intercept/intercept.go b/intercept/intercept.go index 456bd3664..89f711183 100644 --- a/intercept/intercept.go +++ b/intercept/intercept.go @@ -16,7 +16,7 @@ import ( "encoding/json" "errors" "fmt" - "log" + "log/slog" "net" "regexp" "strconv" @@ -309,7 +309,7 @@ func (i *Interceptor) loadLocked() error { if err != nil { if !i.loadFailed { i.loadFailed = true - log.Printf("[intercept] the rule store cannot be read; every tool call is denied until it can: %v", err) + slog.Error("[intercept] the rule store cannot be read; every tool call is denied until it can", "err", err) } return err } diff --git a/llmpool/pool.go b/llmpool/pool.go index 39840f495..dd912d25f 100644 --- a/llmpool/pool.go +++ b/llmpool/pool.go @@ -5,7 +5,7 @@ import ( "errors" "fmt" "iter" - "log" + "log/slog" "regexp" "strconv" "strings" @@ -106,18 +106,18 @@ func (p *Pool) Stream(ctx context.Context, req llm.CompletionRequest) iter.Seq2[ } lastErr = failed if tripped, msg := p.health.RecordCall(ctx, m.ID, true, false, failed); tripped { - log.Printf("[llmpool] profile %q(%s) breaker tripped: %s", m.Name, m.Model, msg) + slog.Warn("[llmpool] profile breaker tripped", "profile", m.Name, "model", m.Model, "reason", msg) } if i+1 < len(order) { n := order[i+1] - log.Printf("[llmpool] LLM failover: %q(%s) → %q(%s), reason: %s", - m.Name, m.Model, n.Name, n.Model, trimErr(failed)) + slog.Warn("[llmpool] LLM failover", "from_profile", m.Name, "from_model", m.Model, + "to_profile", n.Name, "to_model", n.Model, "reason", trimErr(failed)) } } if lastErr == nil { lastErr = ErrExhausted } - log.Printf("[llmpool] failover chain exhausted (all %d profiles failed), last error: %s", len(order), trimErr(lastErr)) + slog.Error("[llmpool] failover chain exhausted, all profiles failed", "profiles", len(order), "last_err", trimErr(lastErr)) yield(llm.StreamEvent{}, fmt.Errorf("%w: %v", ErrExhausted, lastErr)) } } @@ -145,18 +145,18 @@ func (p *Pool) Complete(ctx context.Context, req llm.CompletionRequest) (llm.Mes } lastErr = err if tripped, msg := p.health.RecordCall(ctx, m.ID, false, false, err); tripped { - log.Printf("[llmpool] profile %q(%s) breaker tripped: %s", m.Name, m.Model, msg) + slog.Warn("[llmpool] profile breaker tripped", "profile", m.Name, "model", m.Model, "reason", msg) } if i+1 < len(order) { n := order[i+1] - log.Printf("[llmpool] LLM failover: %q(%s) → %q(%s), reason: %s", - m.Name, m.Model, n.Name, n.Model, trimErr(err)) + slog.Warn("[llmpool] LLM failover", "from_profile", m.Name, "from_model", m.Model, + "to_profile", n.Name, "to_model", n.Model, "reason", trimErr(err)) } } if lastErr == nil { lastErr = ErrExhausted } - log.Printf("[llmpool] failover chain exhausted (all %d profiles failed), last error: %s", len(order), trimErr(lastErr)) + slog.Error("[llmpool] failover chain exhausted, all profiles failed", "profiles", len(order), "last_err", trimErr(lastErr)) return llm.Message{}, "", llm.Usage{}, fmt.Errorf("%w: %v", ErrExhausted, lastErr) } diff --git a/llmrec/context_telemetry.go b/llmrec/context_telemetry.go index edfc1acf6..b4e145337 100644 --- a/llmrec/context_telemetry.go +++ b/llmrec/context_telemetry.go @@ -2,7 +2,7 @@ package llmrec import ( "encoding/json" - "log" + "log/slog" "os" "strings" @@ -169,6 +169,6 @@ func (r *Recorder) recordContext(taskID, worker string, m ContextMetrics, usage Status: status, }) if err != nil { - log.Printf("[llmcontext] insert: %v", err) + slog.Error("[llmcontext] insert failed", "err", err) } } diff --git a/llmrec/llmrec.go b/llmrec/llmrec.go index 0eb75da11..23f2abd6e 100644 --- a/llmrec/llmrec.go +++ b/llmrec/llmrec.go @@ -8,7 +8,7 @@ import ( "encoding/json" "errors" "iter" - "log" + "log/slog" "strings" "time" @@ -363,7 +363,7 @@ func (r *Recorder) recordUsage(ctx context.Context, taskID string, expID int64, Status: status, }) if err != nil { - log.Printf("[llmusage] insert: %v", err) + slog.Error("[llmusage] insert failed", "err", err) } } @@ -424,7 +424,7 @@ func (r *Recorder) record(req llm.CompletionRequest, session, taskID, worker, re } if err := r.pg.InsertLLMRecord(rec); err != nil { - log.Printf("[llmrec] insert: %v", err) + slog.Error("[llmrec] insert failed", "err", err) } }