fix: align Docker Go version with go.mod and optimize logger

- Update Dockerfile to use golang:1.25-alpine to match go.mod (go 1.25.7)
- Optimize logger by avoiding string concatenation in file writes
- Add explicit empty string assignment for fieldStr when no fields

These changes improve build consistency and reduce memory allocations
in the hot logging path, which is important for the project's goal
of running on resource-constrained devices (<10MB RAM).

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
hobostay 2026-02-21 19:02:21 +08:00
parent bb8b9243b7
commit 1612c40f9c
2 changed files with 4 additions and 2 deletions

View file

@ -1,7 +1,7 @@
# ============================================================ # ============================================================
# Stage 1: Build the picoclaw binary # Stage 1: Build the picoclaw binary
# ============================================================ # ============================================================
FROM golang:1.26.0-alpine AS builder FROM golang:1.25-alpine AS builder
RUN apk add --no-cache git make RUN apk add --no-cache git make

View file

@ -119,13 +119,15 @@ func logMessage(level LogLevel, component string, message string, fields map[str
if logger.file != nil { if logger.file != nil {
jsonData, err := json.Marshal(entry) jsonData, err := json.Marshal(entry)
if err == nil { if err == nil {
logger.file.WriteString(string(jsonData) + "\n") logger.file.Write(append(jsonData, '\n'))
} }
} }
var fieldStr string var fieldStr string
if len(fields) > 0 { if len(fields) > 0 {
fieldStr = " " + formatFields(fields) fieldStr = " " + formatFields(fields)
} else {
fieldStr = ""
} }
logLine := fmt.Sprintf("[%s] [%s]%s %s%s", logLine := fmt.Sprintf("[%s] [%s]%s %s%s",