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:
程智超0668000959
2026-06-08 09:08:30 +08:00
parent 875cf4a2d4
commit 1ab442b12c
3 changed files with 24 additions and 9 deletions
+5 -2
View File
@@ -21,6 +21,7 @@ import (
"github.com/sipeed/picoclaw/pkg/config"
"github.com/sipeed/picoclaw/pkg/constants"
"github.com/sipeed/picoclaw/pkg/isolation"
"github.com/sipeed/picoclaw/pkg/logger"
)
var (
@@ -162,7 +163,9 @@ func NewExecToolWithConfig(
denyPatterns = append(denyPatterns, windowsDenyPatterns...)
}
if len(execConfig.CustomDenyPatterns) > 0 {
fmt.Printf("Using custom deny patterns: %v\n", execConfig.CustomDenyPatterns)
logger.InfoCF("tools", "using custom deny patterns", map[string]any{
"patterns": execConfig.CustomDenyPatterns,
})
for _, pattern := range execConfig.CustomDenyPatterns {
re, err := regexp.Compile(pattern)
if err != nil {
@@ -173,7 +176,7 @@ func NewExecToolWithConfig(
}
} else {
// If deny patterns are disabled, we won't add any patterns, allowing all commands.
fmt.Println("Warning: deny patterns are disabled. All commands will be allowed.")
logger.WarnCF("tools", "deny patterns are disabled, all commands will be allowed", nil)
}
for _, pattern := range execConfig.CustomAllowPatterns {
re, err := regexp.Compile(pattern)