集成 Vector 日志处理

This commit is contained in:
2025-03-03 17:14:45 +08:00
parent cc0b74c5c2
commit 4b3cb8e354
8 changed files with 74 additions and 23 deletions

View File

@@ -12,9 +12,6 @@ import (
"sync"
"syscall"
"time"
"github.com/lmittmann/tint"
"github.com/mattn/go-colorable"
)
type Context struct {
@@ -78,19 +75,23 @@ func Start() {
}
func initLog() {
writer := colorable.NewColorable(os.Stdout)
logger := slog.New(tint.NewHandler(writer, &tint.Options{
Level: slog.LevelDebug,
TimeFormat: time.RFC3339,
ReplaceAttr: func(_ []string, attr slog.Attr) slog.Attr {
err, ok := attr.Value.Any().(error)
if !ok {
return attr
}
return tint.Err(err)
},
}))
slog.SetDefault(logger)
// writer := colorable.NewColorable(os.Stdout)
// logger := slog.New(tint.NewHandler(writer, &tint.Options{
// Level: slog.LevelDebug,
// TimeFormat: time.RFC3339,
// ReplaceAttr: func(_ []string, attr slog.Attr) slog.Attr {
// err, ok := attr.Value.Any().(error)
// if !ok {
// return attr
// }
// return tint.Err(err)
// },
// }))
// slog.SetDefault(logger)
handler := slog.NewJSONHandler(os.Stdout, &slog.HandlerOptions{
Level: slog.LevelDebug,
})
slog.SetDefault(slog.New(handler))
}
func startFwdServer(ctx context.Context) error {