Skip to content
Snippets Groups Projects
Commit 586ca759 authored by gbe's avatar gbe
Browse files

Fix panic in unit tests

parent cb25ec83
No related branches found
No related tags found
No related merge requests found
......@@ -40,12 +40,18 @@ func Request(next http.Handler, logger log.Logger) http.Handler {
})
}
// Get returns the logger for the given HTTP request. It panics if r has no logger
// Get returns the logger for the given HTTP request. It will return a logger that discards all writes if r does not have a logger in its context.
func Get(r *http.Request) log.Logger {
return GetContext(r.Context())
}
// GetContext returns the logger for the given context. If ctx has no logger, it panics
// GetContext returns the logger for the given context. If ctx has no logger, it returns
// a logger that will discard all logged events.
func GetContext(ctx context.Context) log.Logger {
return ctx.Value(contextKey("logger")).(log.Logger)
val := ctx.Value(contextKey("logger"))
if val == nil {
val = log.NewNopLogger()
}
return val.(log.Logger)
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment