我正在尝试将一些日志中间件添加到 grpc 服务器,我正在按照他们的 github 上的简单示例进行操作。
https://github.com/grpc-ecosystem/go-grpc-middleware/blob/master/logging/logrus/examples_test.go
我这样设置我的服务器选项:
var (
logrusLogger *logrus.Logger
customFunc grpc_logrus.CodeToLevel
)
func main() {
logrusEntry := logrus.NewEntry(logrusLogger)
lorgusOpts := []grpc_logrus.Option{
grpc_logrus.WithLevels(customFunc),
}
grpc_logrus.ReplaceGrpcLogger(logrusEntry)
opt := []grpc.ServerOption{
grpc.Creds(credentials.NewTLS(tlsConfig)),
grpc_middleware.WithUnaryServerChain(
grpc_auth.UnaryServerInterceptor(auther.Auth),
grpc_logrus.UnaryServerInterceptor(logrusEntry, lorgusOpts...),
),
}
s := grpc.NewServer(opt...)
if err := s.Serve(lis); err != nil {
log.Fatalf("err %+v", err)
}
}
但是,每当我查看日志时,我都会得到一个 nil 指针。
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=0x89edde]
goroutine 23 [running]:
github.com/grpc-ecosystem/go-grpc-middleware/logging/logrus.UnaryServerInterceptor.func1(0xb2e640, 0xc00026c390, 0x9df7a0, 0xc0000adfc0, 0xc00018caa0, 0xc00018cac0, 0xb2e640, 0xc00026c390, 0x0, 0x0)
/go/pkg/mod/github.com/grpc-ecosystem/go-grpc-middleware@v1.2.0/logging/logrus/server_interceptors.go:37 +0x1be
github.com/grpc-ecosystem/go-grpc-middleware.ChainUnaryServer.func1.1.1(0xb2e640, 0xc00026c390, 0x9df7a0, 0xc0000adfc0, 0x0, 0x0, 0x0, 0xc0000adfc0)
/go/pkg/mod/github.com/grpc-ecosystem/go-grpc-middleware@v1.2.0/chain.go:25 +0x63
github.com/grpc-ecosystem/go-grpc-middleware/auth.UnaryServerInterceptor.func1(0xb2e640, 0xc00026c390, 0x9df7a0, 0xc0000adfc0, 0xc00018caa0, 0xc00018cae0, 0x89ceda, 0x9f24e0, 0xc00018cb00, 0xc00018caa0)
倚天杖
拉风的咖菲猫
万千封印
相关分类