Add a function to inject a logger into a context
ernesto-jimenez opened this issue · 1 comments
ernesto-jimenez commented
Right now, clue/log
is the only package that can define a middleware like log.HTTP
, since ctxLogger
is unexported.
It's feasible other people might have to develop their own middlewares, so it would be good to have something like:
log.WithContext(requestCtx, loggerCtx)
// Maybe include this too:
log.MustContainLogger(ctx)
// within clue
func MustContainLogger(logCtx context.Context) {
l := logCtx.Value(ctxLogger)
if l == nil {
panic("provided context without log.Context()")
}
}
It would allow things like:
func WorkerLog(logCtx context.Context) func(worker.Handler) worker.Handler {
...
}
raphael commented
Makes sense! Left a few comments in the commit, we can merge once these are addressed.