1 Star 0 Fork 0

peter/fabric

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
fields.go 975 Bytes
一键复制 编辑 原始数据 按行查看 历史
/*
Copyright IBM Corp. All Rights Reserved.
SPDX-License-Identifier: Apache-2.0
*/
package grpclogging
import (
"github.com/gogo/protobuf/proto"
"github.com/golang/protobuf/jsonpb"
"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})
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/peter_code_git/fabric.git
git@gitee.com:peter_code_git/fabric.git
peter_code_git
fabric
fabric
v1.4.7

搜索帮助