feat!: FromRequest and FromCtx will return the global logger if the one
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
ci/woodpecker/tag/woodpecker Pipeline was successful

extracted is disabled
This commit is contained in:
Marvin Preuss 2022-02-18 15:41:57 +01:00
parent 0e1d0c345a
commit 0aada80108

View File

@ -24,13 +24,27 @@ func GetUUID(r *http.Request) (string, bool) {
}
// FromRequest returns a logger with the UUID set from request.
// If no one could be found, it will return the global one.
func FromRequest(r *http.Request) zerolog.Logger {
l := hlog.FromRequest(r)
if l.GetLevel() == zerolog.Disabled {
return log.Logger
}
return *hlog.FromRequest(r)
}
// FromCtx returns a logger with the UUID set from ctx.
// If no one could be found, it will return the global one.
func FromCtx(ctx context.Context) zerolog.Logger {
return *log.Ctx(ctx)
l := *log.Ctx(ctx)
if l.GetLevel() == zerolog.Disabled {
return log.Logger
}
return l
}
func Handler(log zerolog.Logger) func(http.Handler) http.Handler {