mirror of
https://github.com/sipeed/picoclaw.git
synced 2026-06-12 18:08:54 +00:00
refactor: replace log.Printf/fmt.Printf with structured logger
Replace raw log.Printf and fmt.Printf calls in pkg/state, pkg/agent, and pkg/tools with structured logger calls (WarnCF/InfoCF). This ensures warnings and info messages are routed through the configured logging infrastructure instead of raw stderr/stdout.
This commit is contained in:
+15
-5
@@ -3,13 +3,13 @@ package state
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"log"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/sipeed/picoclaw/pkg/fileutil"
|
||||
"github.com/sipeed/picoclaw/pkg/logger"
|
||||
)
|
||||
|
||||
// State represents the persistent state for a workspace.
|
||||
@@ -41,7 +41,10 @@ func NewManager(workspace string) *Manager {
|
||||
|
||||
// Create state directory if it doesn't exist
|
||||
if err := os.MkdirAll(stateDir, 0o700); err != nil {
|
||||
log.Printf("[WARN] state: failed to create state directory %s: %v", stateDir, err)
|
||||
logger.WarnCF("state", "failed to create state directory", map[string]any{
|
||||
"dir": stateDir,
|
||||
"error": err.Error(),
|
||||
})
|
||||
}
|
||||
|
||||
sm := &Manager{
|
||||
@@ -57,15 +60,22 @@ func NewManager(workspace string) *Manager {
|
||||
if err := json.Unmarshal(data, sm.state); err == nil {
|
||||
// Migrate to new location
|
||||
if err := sm.saveAtomic(); err != nil {
|
||||
log.Printf("[WARN] state: failed to save state: %v", err)
|
||||
logger.WarnCF("state", "failed to save state", map[string]any{
|
||||
"error": err.Error(),
|
||||
})
|
||||
}
|
||||
log.Printf("[INFO] state: migrated state from %s to %s", oldStateFile, stateFile)
|
||||
logger.InfoCF("state", "migrated state", map[string]any{
|
||||
"from": oldStateFile,
|
||||
"to": stateFile,
|
||||
})
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// Load from new location
|
||||
if err := sm.load(); err != nil {
|
||||
log.Printf("[WARN] state: failed to load state: %v", err)
|
||||
logger.WarnCF("state", "failed to load state", map[string]any{
|
||||
"error": err.Error(),
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user