]> git.giacomolli.uk - onechat/blobdiff - turn.go
Write the log rules in the Go skill
[onechat] / turn.go
diff --git a/turn.go b/turn.go
index 42886049ffb934582fea0259145aa85e054d4863..637d783b70dfb8c5eb80eb521e7e0510b1db13fc 100644 (file)
--- a/turn.go
+++ b/turn.go
@@ -4,7 +4,7 @@ import (
        "context"
        "errors"
        "fmt"
-       "log"
+       "log/slog"
        "path/filepath"
        "sync"
        "time"
@@ -14,7 +14,7 @@ import (
 // WhatsApp link and the schedules of its tools. Its calls go through client,
 // and notify gets each event. The clock gives the date of a turn. logger gets
 // the failed turns and the ends of the subagents.
-func newTurnLoop(agent *Agent, memory *Memory, subagents *Subagents, whatsapp *WhatsApp, schedules *Schedules, client ChainClient, clock func() time.Time, logger *log.Logger, notify func(Event)) (*TurnLoop, error) {
+func newTurnLoop(agent *Agent, memory *Memory, subagents *Subagents, whatsapp *WhatsApp, schedules *Schedules, client ChainClient, clock func() time.Time, logger *slog.Logger, notify func(Event)) (*TurnLoop, error) {
        layout, err := loadViewLayout(filepath.Join(agent.dir, viewLayoutFileName))
        if err != nil {
                return nil, err
@@ -92,7 +92,7 @@ type TurnLoop struct {
        runs   *SubagentRuns
        layout *ViewLayout
        clock  func() time.Time
-       logger *log.Logger
+       logger *slog.Logger
        notify func(Event)
        wake   chan struct{}
 
@@ -334,7 +334,7 @@ func (l *TurnLoop) turn(ctx context.Context) error {
        err := l.chain(ctx)
        if err != nil && !errors.Is(err, errChainLogWrite) {
                if ctx.Err() == nil {
-                       l.logger.Printf("turn failed: %v", err)
+                       l.logger.Error("turn failed", "err", err)
                }
 
                l.notify(Event{