Documentation ¶
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func StreamServerInterceptor ¶
func StreamServerInterceptor(logger *zap.Logger, opts ...Option) grpc.StreamServerInterceptor
Example ¶
package main import ( "context" "github.com/acrazing/ctxzap" "github.com/acrazing/ctxzap/grpc_zap" "go.uber.org/zap" "google.golang.org/grpc" ) func main() { logger := zap.NewExample() _ = grpc.NewServer( grpc.ChainUnaryInterceptor( grpc_zap.UnaryServerInterceptor(logger, grpc_zap.WithAccessLog(true, true)), ), grpc.ChainStreamInterceptor( grpc_zap.StreamServerInterceptor(logger, grpc_zap.WithEventLog(true, true)), ), ) // In any context based method called by grpc servers _ = func(ctx context.Context) { // add a field to the context, this field will always be printed in the next // log calls with the context. ctxzap.AddFields(ctx, zap.String("data", "1")) // replace an existing field or append it to the context ctxzap.ReplaceField(ctx, zap.String("data", "2")) // print a log ctxzap.Info(ctx, "call with data", zap.String("value", "2")) } }
Output:
func UnaryServerInterceptor ¶
func UnaryServerInterceptor(logger *zap.Logger, opts ...Option) grpc.UnaryServerInterceptor
Types ¶
type Option ¶
type Option interface {
// contains filtered or unexported methods
}
func WithAccessLog ¶
WithAccessLog enable/disable access log both started & finished log are enabled for stream server by default only finished log is enabled for unary server by default
func WithErrorFieldsFunc ¶
WithErrorFieldsFunc extract error detail fields
func WithEventLog ¶
WithEventLog enable/disable event log only works with stream interceptor both send/recv are disabled by default
func WithFieldsFunc ¶
WithFieldsFunc attach custom zap fields to all the logs please note the values are extracted synchronously.
func WithMetadataFields ¶
WithMetadataFields attach all the specified keys to all the logs please note the values are extracted synchronously.
Click to show internal directories.
Click to hide internal directories.