traefik/pkg/logs/log.go

36 lines
706 B
Go
Raw Permalink Normal View History

2022-11-21 17:36:05 +00:00
package logs
import (
"fmt"
"github.com/rs/zerolog"
)
func NoLevel(logger zerolog.Logger, level zerolog.Level) zerolog.Logger {
return logger.Hook(NewNoLevelHook(logger.GetLevel(), level))
}
type NoLevelHook struct {
minLevel zerolog.Level
level zerolog.Level
}
func NewNoLevelHook(minLevel zerolog.Level, level zerolog.Level) *NoLevelHook {
return &NoLevelHook{minLevel: minLevel, level: level}
}
func (n NoLevelHook) Run(e *zerolog.Event, level zerolog.Level, _ string) {
if n.minLevel > n.level {
e.Discard()
return
}
if level == zerolog.NoLevel {
e.Str("level", n.level.String())
}
}
func msgFunc(i ...any) func() string {
return func() string { return fmt.Sprint(i...) }
}