Merge pull request #523 from rahulremany/chore/slog-llmpool-llmrec-intercept-db

chore: migrate log.Printf to log/slog in llmpool, llmrec, intercept and db
This commit is contained in:
BaaRai
2026-11-26 22:25:00 +01:00
committed by GitHub
8 changed files with 28 additions and 28 deletions
+2 -2
View File
@@ -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
}
+2 -2
View File
@@ -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)
}
}
+5 -5
View File
@@ -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
}
+3 -3
View File
@@ -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
}
+2 -2
View File
@@ -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
}
+9 -9
View File
@@ -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)
}
+2 -2
View File
@@ -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)
}
}
+3 -3
View File
@@ -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)
}
}