mirror of
https://github.com/BaaRai/ARTEX.git
synced 2026-11-27 10:20:54 +08:00
chore: migrate log.Printf to log/slog in server management and control
This commit is contained in:
@@ -9,7 +9,7 @@ import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"log"
|
||||
"log/slog"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"os"
|
||||
@@ -242,7 +242,7 @@ func (s *Server) seedPythonInterpreter() {
|
||||
}
|
||||
if p := detectPython(); p != "" {
|
||||
_ = s.m.pg.SetSetting(settingPythonInterp, p)
|
||||
log.Printf("[custom-tool] auto-detected python interpreter: %s", p)
|
||||
slog.Info("[custom-tool] auto-detected python interpreter", "path", p)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+8
-8
@@ -2,7 +2,7 @@ package server
|
||||
|
||||
import (
|
||||
"context"
|
||||
"log"
|
||||
"log/slog"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
@@ -43,7 +43,7 @@ func newLLMHealthRegistry(ctx context.Context, pg *db.DB) (*llmpool.Registry, *h
|
||||
st.OpenUntil = *h.OpenUntil
|
||||
}
|
||||
reg.Restore(h.ProfileID, st)
|
||||
log.Printf("[llmpool] restored circuit-breaker state: profile #%d cooling until %s", h.ProfileID, st.OpenUntil.Format(time.RFC3339))
|
||||
slog.Info("[llmpool] restored circuit-breaker state", "profile_id", h.ProfileID, "cooling_until", st.OpenUntil.Format(time.RFC3339))
|
||||
}
|
||||
}
|
||||
return reg, syncer
|
||||
@@ -103,7 +103,7 @@ func (s *Server) FlushLLMHealth() {
|
||||
select {
|
||||
case <-s.llmHealthSync.done:
|
||||
case <-time.After(5 * time.Second):
|
||||
log.Printf("[llmpool] timed out flushing circuit-breaker state")
|
||||
slog.Warn("[llmpool] timed out flushing circuit-breaker state")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -114,7 +114,7 @@ func (h *healthSync) enqueue(id int64, op healthOp) {
|
||||
if h.stopped {
|
||||
h.mu.Unlock()
|
||||
if err := h.apply(id, op); err != nil {
|
||||
log.Printf("[llmpool] write circuit-breaker profile #%d: %v", id, err)
|
||||
slog.Error("[llmpool] write circuit-breaker profile failed", "profile_id", id, "err", err)
|
||||
}
|
||||
return
|
||||
}
|
||||
@@ -198,7 +198,7 @@ func (h *healthSync) apply(id int64, op healthOp) error {
|
||||
func (h *healthSync) write(batch map[int64]healthOp) (failed bool) {
|
||||
for id, op := range batch {
|
||||
if err := h.apply(id, op); err != nil {
|
||||
log.Printf("[llmpool] write circuit-breaker profile #%d: %v", id, err)
|
||||
slog.Error("[llmpool] write circuit-breaker profile failed", "profile_id", id, "err", err)
|
||||
h.restore(id, op)
|
||||
failed = true
|
||||
}
|
||||
@@ -214,7 +214,7 @@ func (h *healthSync) finish() {
|
||||
h.mu.Unlock()
|
||||
for id, op := range batch {
|
||||
if err := h.apply(id, op); err != nil {
|
||||
log.Printf("[llmpool] write circuit-breaker profile #%d: %v", id, err)
|
||||
slog.Error("[llmpool] write circuit-breaker profile failed", "profile_id", id, "err", err)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -273,7 +273,7 @@ func (s *Server) poolChain(headID int64, headProv llm.Provider, headCfg agent.Co
|
||||
}
|
||||
profs, err := s.m.pg.PoolProfiles()
|
||||
if err != nil {
|
||||
log.Printf("[llmpool] failed to read the pool chain: %v", err)
|
||||
slog.Error("[llmpool] failed to read pool chain", "err", err)
|
||||
return nil
|
||||
}
|
||||
var head *db.LLMProfile
|
||||
@@ -326,7 +326,7 @@ func (s *Server) poolForActive(activeID int64, prov llm.Provider, cfg agent.Conf
|
||||
for _, m := range pool.Members() {
|
||||
names = append(names, m.Name+"/"+m.Model)
|
||||
}
|
||||
log.Printf("[llmpool] LLM pooling enabled, chain (%d): %v", len(names), names)
|
||||
slog.Info("[llmpool] LLM pooling enabled", "count", len(names), "chain", names)
|
||||
return pool
|
||||
}
|
||||
|
||||
|
||||
+10
-10
@@ -9,7 +9,7 @@ import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"log"
|
||||
"log/slog"
|
||||
"mime"
|
||||
"net"
|
||||
"net/http"
|
||||
@@ -207,7 +207,7 @@ func (s *Server) abortTaskDelete(taskID string) {
|
||||
state := task.lifecycleSnapshot()
|
||||
keepPaused = state.Paused || state.Queued
|
||||
if getErr != nil {
|
||||
log.Printf("[task-delete] task %s failed to read persisted state, restoring the barrier from in-memory state: %v", taskID, getErr)
|
||||
slog.Warn("[task-delete] failed to read persisted state, restoring barrier from in-memory state", "task_id", taskID, "err", getErr)
|
||||
}
|
||||
} else if getErr == nil {
|
||||
// The request targeted a task that does not exist. Do not retain a
|
||||
@@ -361,7 +361,7 @@ func (s *Server) pgCreateAgent(w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
// starter prompt so the editor shows something editable from the start.
|
||||
if err := pg.SeedPromptIfEmpty(a.ID, agent.DefaultAssistantPrompt); err != nil {
|
||||
log.Printf("[agents] failed to seed starter prompt for %s: %v", a.Key, err)
|
||||
slog.Error("[agents] failed to seed starter prompt", "agent", a.Key, "err", err)
|
||||
}
|
||||
writeJSON(w, 200, agentDTO(a))
|
||||
}
|
||||
@@ -409,10 +409,10 @@ func (s *Server) pgDeleteAgent(w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
if err := pg.RemoveAgentFromToolBindings(a.Key); err != nil {
|
||||
log.Printf("[agents] failed to clean up tool bindings for %s: %v", a.Key, err)
|
||||
slog.Error("[agents] failed to clean up tool bindings", "agent", a.Key, "err", err)
|
||||
}
|
||||
if err := pg.DeleteTriggersForAgent(a.Key); err != nil {
|
||||
log.Printf("[agents] failed to clean up triggers for %s: %v", a.Key, err)
|
||||
slog.Error("[agents] failed to clean up triggers", "agent", a.Key, "err", err)
|
||||
}
|
||||
writeJSON(w, 200, map[string]any{"deleted": a.Key})
|
||||
}
|
||||
@@ -850,7 +850,7 @@ func (s *Server) pgListTools(w http.ResponseWriter, r *http.Request) {
|
||||
// catalog query, so agent assembly never pays for this aggregate.
|
||||
counts, countErr := pg.ToolUsageCounts()
|
||||
if countErr != nil {
|
||||
log.Printf("[tools] failed to read call stats: %v", countErr)
|
||||
slog.Warn("[tools] failed to read call stats", "err", countErr)
|
||||
} else {
|
||||
for _, tool := range ts {
|
||||
tool.Calls = counts[tool.Key]
|
||||
@@ -1071,7 +1071,7 @@ func (s *Server) pgSaveMCP(w http.ResponseWriter, r *http.Request) {
|
||||
m.ID = id
|
||||
ctx, cancel := context.WithTimeout(r.Context(), 45*time.Second)
|
||||
if derr := s.discoverAndCacheMCP(ctx, &m); derr != nil {
|
||||
log.Printf("[mcp] tool discovery after adding %s failed: %v", m.Name, derr)
|
||||
slog.Error("[mcp] tool discovery failed after adding mcp", "mcp", m.Name, "err", derr)
|
||||
}
|
||||
cancel()
|
||||
}
|
||||
@@ -1182,7 +1182,7 @@ func (s *Server) fsListSkills(w http.ResponseWriter, r *http.Request) {
|
||||
if s.m.pg != nil {
|
||||
stats, err := s.m.pg.SkillStats()
|
||||
if err != nil {
|
||||
log.Printf("[skills] failed to read call stats: %v", err)
|
||||
slog.Warn("[skills] failed to read call stats", "err", err)
|
||||
}
|
||||
for _, st := range stats {
|
||||
statBySkill[st.Skill] = st
|
||||
@@ -1437,7 +1437,7 @@ func warnBrokenSkills(dir string) {
|
||||
if s.Dir == "" || s.Name == filepath.Base(s.Dir) {
|
||||
continue
|
||||
}
|
||||
log.Printf("[skill] %s: frontmatter did not parse (loaded under the directory name; description and mcps are empty) - fix the YAML in %s", s.Name, filepath.Join(s.Dir, "SKILL.md"))
|
||||
slog.Warn("[skill] frontmatter did not parse", "skill", s.Name, "path", filepath.Join(s.Dir, "SKILL.md"))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2298,7 +2298,7 @@ func (s *Server) restoreTasksAfterProfileDelete(pg *db.DB) {
|
||||
// paused task remains paused and terminal tasks remain immutable.
|
||||
if !isTerminalStatus(task.lifecycleSnapshot().Status) && s.taskRuntimeAvailable(task, "planner", "worker") {
|
||||
if _, reopenErr := task.Store.ReopenIntentsByBlockedReason(db.IntentBlockedLLMQuota); reopenErr != nil {
|
||||
log.Printf("[llm-profile] task %s reopen quota-blocked intents after profile delete: %v", task.ID, reopenErr)
|
||||
slog.Warn("[llm-profile] reopen quota-blocked intents failed after profile delete", "task_id", task.ID, "err", reopenErr)
|
||||
}
|
||||
}
|
||||
task.Notify()
|
||||
|
||||
@@ -4,7 +4,7 @@ import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"log"
|
||||
"log/slog"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
@@ -157,7 +157,7 @@ func (s *Server) deleteRemoteTaskArchive(job *pgdb.TaskArchive) error {
|
||||
}
|
||||
if err := s.recoverRemoteArchiveJournal(journal); err != nil {
|
||||
// The task is gone; the durable outbox retries the remaining object cleanup.
|
||||
log.Printf("[task-archive] archive %d deleted; remote cleanup pending: %v", job.ID, err)
|
||||
slog.Info("[task-archive] archive deleted, remote cleanup pending", "archive_id", job.ID, "err", err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -4,7 +4,7 @@ import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"log"
|
||||
"log/slog"
|
||||
"net/http"
|
||||
"strings"
|
||||
|
||||
@@ -145,7 +145,7 @@ func (s *Server) applyTaskControlWithCause(t *Task, action string, pauseCause er
|
||||
default:
|
||||
return out, fmt.Errorf("action must be pause|resume")
|
||||
}
|
||||
log.Printf("[task] #%s %s", t.ID, map[string]string{"pause": "paused", "resume": "resumed"}[action])
|
||||
slog.Info("[task] task state changed", "task_id", t.ID, "action", map[string]string{"pause": "paused", "resume": "resumed"}[action])
|
||||
return out, nil
|
||||
}
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@ package server
|
||||
import (
|
||||
"database/sql"
|
||||
"errors"
|
||||
"log"
|
||||
"log/slog"
|
||||
"net/http"
|
||||
"strconv"
|
||||
)
|
||||
@@ -23,7 +23,7 @@ func (s *Server) taskOutcome(w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
if err != nil {
|
||||
log.Printf("[tasks] outcome query failed for %d: %v", id, err)
|
||||
slog.Error("[tasks] outcome query failed", "task_id", id, "err", err)
|
||||
writeErr(w, 500, "outcome query failed")
|
||||
return
|
||||
}
|
||||
|
||||
@@ -5,7 +5,7 @@ import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"log"
|
||||
"log/slog"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"strconv"
|
||||
@@ -145,7 +145,7 @@ func (m *Manager) reloadTamperHooks() {
|
||||
}
|
||||
rows, err := m.pg.ListTrafficTamperHooks()
|
||||
if err != nil {
|
||||
log.Printf("[traffic] tampering hooks not reloaded: %v", err)
|
||||
slog.Warn("[traffic] tampering hooks not reloaded", "err", err)
|
||||
return
|
||||
}
|
||||
defs := make([]traffic.HookDef, 0, len(rows))
|
||||
@@ -165,7 +165,7 @@ func (m *Manager) reloadTamperHooks() {
|
||||
loadErrs[id] = msg
|
||||
}
|
||||
for id, msg := range loadErrs {
|
||||
log.Printf("[traffic] tampering hook %d not loaded: %s", id, msg)
|
||||
slog.Warn("[traffic] tampering hook not loaded", "hook_id", id, "msg", msg)
|
||||
}
|
||||
m.hookLoadErrs = loadErrs
|
||||
m.hookSet.Store(hs)
|
||||
|
||||
+3
-3
@@ -3,7 +3,7 @@ package server
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"log"
|
||||
"log/slog"
|
||||
"net"
|
||||
"net/http"
|
||||
"strconv"
|
||||
@@ -23,7 +23,7 @@ import (
|
||||
// no base_url/model returns nil, and report_finding behaves exactly as before.
|
||||
func (s *Server) triageClient() agent.TriageClient {
|
||||
id := s.triageProfileID()
|
||||
log.Printf("[triage] triageClient: profile_id=%d", id)
|
||||
slog.Info("[triage] initialized triage client", "profile_id", id)
|
||||
if id <= 0 {
|
||||
return nil
|
||||
}
|
||||
@@ -52,7 +52,7 @@ func (s *Server) triageHTTPClient(baseURL string) *http.Client {
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
|
||||
defer cancel()
|
||||
if _, err := g.validateURL(ctx, baseURL, "triage"); err != nil {
|
||||
log.Printf("[triage] base_url refused (%v); dedup stays off", err)
|
||||
slog.Warn("[triage] base_url refused, dedup stays off", "err", err)
|
||||
return nil
|
||||
}
|
||||
var tr *http.Transport
|
||||
|
||||
Reference in New Issue
Block a user