logger adjust

This commit is contained in:
mr
2026-04-10 15:12:39 +02:00
parent a8fa18520c
commit 115d175d45
5 changed files with 39 additions and 32 deletions

View File

@@ -2,8 +2,8 @@ package daemons
import (
"bufio"
"fmt"
"io"
"strings"
"github.com/rs/zerolog"
)
@@ -13,11 +13,28 @@ type Executor interface {
LaunchMonitor(args []string, execID string, ns string, l zerolog.Logger)
}
// logExecution streams lines from reader and re-logs them at the appropriate
// level by inspecting the zerolog level token already present in each line.
// Lines that contain " ERR " or " error" (case-insensitive) are emitted at
// Error so that they are visible beyond Debug-only sinks.
func logExecution(reader io.ReadCloser, l zerolog.Logger) {
scanner := bufio.NewScanner(reader)
// Increase buffer to 1 MB to handle wide JSON payloads.
scanner.Buffer(make([]byte, 1024*1024), 1024*1024)
for scanner.Scan() {
output := scanner.Text()
fmt.Println(output)
l.Debug().Msg(output)
line := scanner.Text()
switch {
case strings.Contains(line, " ERR ") || strings.Contains(line, "level=error"):
l.Error().Msg(line)
case strings.Contains(line, " WRN ") || strings.Contains(line, "level=warning"):
l.Warn().Msg(line)
case strings.Contains(line, " INF ") || strings.Contains(line, "level=info"):
l.Info().Msg(line)
default:
l.Debug().Msg(line)
}
}
if err := scanner.Err(); err != nil {
l.Error().Err(err).Msg("log scanner error")
}
}