feat(parser/log): support specify log level
All checks were successful
submodules sync / sync (push) Successful in 31s
build / build (push) Successful in 1m5s
build / trigger-build-image (push) Successful in 6s

This commit is contained in:
张泊明518370910136 2025-02-01 21:52:26 -05:00
parent d6da8c8fa7
commit 6b3ebebecb
GPG Key ID: D47306D7062CDA9D

View File

@ -1,6 +1,7 @@
package log package log
import ( import (
"context"
"encoding/json" "encoding/json"
"fmt" "fmt"
"log/slog" "log/slog"
@ -11,6 +12,7 @@ import (
type Conf struct { type Conf struct {
FileName string `default:"stdout"` FileName string `default:"stdout"`
Msg string `default:"log msg"` Msg string `default:"log msg"`
Level int `default:"0"`
} }
type Log struct{} type Log struct{}
@ -30,7 +32,12 @@ func Parse(executorResult stage.ExecutorResult, conf Conf) stage.ParserResult {
for key, value := range data { for key, value := range data {
args = append(args, key, value) args = append(args, key, value)
} }
slog.Info(conf.Msg, args...) slog.Default().Log(
context.Background(),
slog.Level(conf.Level),
conf.Msg,
args...,
)
return stage.ParserResult{ return stage.ParserResult{
Score: 0, Score: 0,
Comment: "", Comment: "",