You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am writing some database logging middleware that I would like tointeract with the request scoped logger. I don't expect that this middleware will always be used in a GRPC service context alongside grpc_zap and ctxzap, so I'd like for it to be able to fall back to some default logger when necessary.
There isn't a clear way to do this right now, since nullLogger is unexported.
To support this use case I'd like to propose adding one of:
// Extract takes the call-scoped Logger from grpc_zap middleware.//// It always returns a Logger that has all the grpc_ctxtags updated.funcExtract(ctx context.Context) *zap.Logger {
l, ok:=MaybeExtract(ctx)
if!ok {
returnnullLogger
}
returnl
}
// Extract takes the call-scoped Logger from grpc_zap middleware, if one exists, otherwise// returns nil and false.//// It always returns a Logger that has all the grpc_ctxtags updated.funcMaybeExtract(ctx context.Context) (*zap.Logger, bool) {
l, ok:=ctx.Value(ctxMarkerKey).(*ctxLogger)
if!ok||l==nil {
returnnil, false
}
// Add grpc_ctxtags tags metadata until now.fields:=TagsToFields(ctx)
// Add zap fields added until now.fields=append(fields, l.fields...)
returnl.logger.With(fields...), true
}
The text was updated successfully, but these errors were encountered:
Great idea, but not sure why it has to be hosted in go-grpc-middlewares. The v2 version has logging.ExtractFields that should allow you to create your own context logger. Closing, unless you think that's not enough, we can reopen (:
I am writing some database logging middleware that I would like tointeract with the request scoped logger. I don't expect that this middleware will always be used in a GRPC service context alongside
grpc_zap
andctxzap
, so I'd like for it to be able to fall back to some default logger when necessary.There isn't a clear way to do this right now, since
nullLogger
is unexported.To support this use case I'd like to propose adding one of:
or
The text was updated successfully, but these errors were encountered: