gitee.com/ks-custle/core-gm@v0.0.0-20230922171213-b83bdd97b62c/go-grpc-middleware/logging/logrus/grpclogger.go (about) 1 // Copyright 2017 Michal Witkowski. All Rights Reserved. 2 // See LICENSE for licensing terms. 3 4 package grpc_logrus 5 6 import ( 7 "gitee.com/ks-custle/core-gm/grpc/grpclog" 8 "github.com/sirupsen/logrus" 9 ) 10 11 // ReplaceGrpcLogger sets the given logrus.Logger as a gRPC-level logger. 12 // This should be called *before* any other initialization, preferably from init() functions. 13 func ReplaceGrpcLogger(logger *logrus.Entry) { 14 // grpclog.SetLogger is deprecated, use SetLoggerV2 instead. 15 //grpclog.SetLogger(logger.WithField("system", SystemField)) 16 grpclog.SetLoggerV2(NewEntry(logger.WithField("system", SystemField))) 17 } 18 19 type Entry struct { 20 logrus.Entry 21 } 22 23 // V 为 Entry 绑定方法 V(l int) bool 24 func (e *Entry) V(l int) bool { 25 // reports whether verbosity level l is at least the requested verbose level. 26 return int(e.Logger.Level) >= l 27 } 28 29 func NewEntry(e *logrus.Entry) *Entry { 30 return &Entry{*e} 31 }