logger adjust
This commit is contained in:
@@ -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")
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user