6 Star 44 Fork 25

Hyperledger / fabric

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
fields.go 977 Bytes
一键复制 编辑 原始数据 按行查看 历史
/*
Copyright IBM Corp. All Rights Reserved.
SPDX-License-Identifier: Apache-2.0
*/
package grpclogging
import (
"github.com/golang/protobuf/jsonpb"
"github.com/golang/protobuf/proto"
"go.uber.org/zap"
"go.uber.org/zap/zapcore"
)
type protoMarshaler struct {
jsonpb.Marshaler
message proto.Message
}
func (m *protoMarshaler) MarshalJSON() ([]byte, error) {
out, err := m.Marshaler.MarshalToString(m.message)
if err != nil {
return nil, err
}
return []byte(out), nil
}
func ProtoMessage(key string, val interface{}) zapcore.Field {
if pm, ok := val.(proto.Message); ok {
return zap.Reflect(key, &protoMarshaler{message: pm})
}
return zap.Any(key, val)
}
func Error(err error) zapcore.Field {
if err == nil {
return zap.Skip()
}
// Wrap the error so it no longer implements fmt.Formatter. This will prevent
// zap from adding the "verboseError" field to the log record that includes a
// full stack trace.
return zap.Error(struct{ error }{err})
}
1
https://gitee.com/hyperledger/fabric.git
git@gitee.com:hyperledger/fabric.git
hyperledger
fabric
fabric
v2.1.1

搜索帮助