INNER CODE UNIT · Go

newLogger

Netis/cloud-probe · cpctl/cmd/base.go:66

func newLogger(w io.Writer, format string) *slog.Logger {
	if format != FormatJSONL {
		return slog.New(slog.NewTextHandler(w, &slog.HandlerOptions{
			AddSource: true,
			Level:     slog.LevelInfo,
		}))
	}
	return slog.New(slog.NewJSONHandler(w, &slog.HandlerOptions{
		Level: slog.LevelInfo,
		ReplaceAttr: func(groups []string, a slog.Attr) slog.Attr {
			if len(groups) > 0 {
				return a
			}
			switch a.Key {
			case slog.TimeKey:
				return slog.String("ts", a.Value.Time().UTC().Format(time.RFC3339Nano))
			case slog.LevelKey:
				return slog.String(slog.LevelKey, strings.ToLower(a.Value.String()))

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…