Adapts a zap logger to gRPC's logger interface with level mapping.
// Source: https://github.com/milvus-io/milvus | License: Apache-2.0 | Copyright You must retain, in the Source form of any Derivative Works
// Provided via justclaw.it.com; keep this notice with the code.
package mlog
import (
"strings"
"go.uber.org/zap"
"go.uber.org/zap/zapcore"
"go.uber.org/zap/zapgrpc"
"google.golang.org/grpc/grpclog"
)
// NewGRPCLogger adapts a zap logger to gRPC's logger interface.
func NewGRPCLogger(logger *zap.Logger, level string) grpclog.LoggerV2 {
grpcLevel := grpcLogLevel(level)
if logger.Core().Enabled(grpcLevel) {
logger = logger.WithOptions(zap.IncreaseLevel(grpcLevel))
}
return zapgrpc.NewLogger(logger)
}
func grpcLogLevel(level string) zapcore.Level {
switch {
case strings.EqualFold(level, "INFO"):
return zapcore.InfoLevel
case strings.
... (truncated -- full source via MCP)
See the full source, get the GitHub permalink, and search for more like it.
Get a free API key