gRPC migration
Change-Id: I3129ae27d7ee12a23c7046f0d877e8064f2fd7f4
diff --git a/vendor/go.uber.org/zap/zapcore/json_encoder.go b/vendor/go.uber.org/zap/zapcore/json_encoder.go
index 9aec4ea..5cf7d91 100644
--- a/vendor/go.uber.org/zap/zapcore/json_encoder.go
+++ b/vendor/go.uber.org/zap/zapcore/json_encoder.go
@@ -145,15 +145,29 @@
}
}
-func (enc *jsonEncoder) AddReflected(key string, obj interface{}) error {
+var nullLiteralBytes = []byte("null")
+
+// Only invoke the standard JSON encoder if there is actually something to
+// encode; otherwise write JSON null literal directly.
+func (enc *jsonEncoder) encodeReflected(obj interface{}) ([]byte, error) {
+ if obj == nil {
+ return nullLiteralBytes, nil
+ }
enc.resetReflectBuf()
- err := enc.reflectEnc.Encode(obj)
+ if err := enc.reflectEnc.Encode(obj); err != nil {
+ return nil, err
+ }
+ enc.reflectBuf.TrimNewline()
+ return enc.reflectBuf.Bytes(), nil
+}
+
+func (enc *jsonEncoder) AddReflected(key string, obj interface{}) error {
+ valueBytes, err := enc.encodeReflected(obj)
if err != nil {
return err
}
- enc.reflectBuf.TrimNewline()
enc.addKey(key)
- _, err = enc.buf.Write(enc.reflectBuf.Bytes())
+ _, err = enc.buf.Write(valueBytes)
return err
}
@@ -222,7 +236,9 @@
func (enc *jsonEncoder) AppendDuration(val time.Duration) {
cur := enc.buf.Len()
- enc.EncodeDuration(val, enc)
+ if e := enc.EncodeDuration; e != nil {
+ e(val, enc)
+ }
if cur == enc.buf.Len() {
// User-supplied EncodeDuration is a no-op. Fall back to nanoseconds to keep
// JSON valid.
@@ -236,14 +252,12 @@
}
func (enc *jsonEncoder) AppendReflected(val interface{}) error {
- enc.resetReflectBuf()
- err := enc.reflectEnc.Encode(val)
+ valueBytes, err := enc.encodeReflected(val)
if err != nil {
return err
}
- enc.reflectBuf.TrimNewline()
enc.addElementSeparator()
- _, err = enc.buf.Write(enc.reflectBuf.Bytes())
+ _, err = enc.buf.Write(valueBytes)
return err
}
@@ -254,9 +268,18 @@
enc.buf.AppendByte('"')
}
+func (enc *jsonEncoder) AppendTimeLayout(time time.Time, layout string) {
+ enc.addElementSeparator()
+ enc.buf.AppendByte('"')
+ enc.buf.AppendTime(time, layout)
+ enc.buf.AppendByte('"')
+}
+
func (enc *jsonEncoder) AppendTime(val time.Time) {
cur := enc.buf.Len()
- enc.EncodeTime(val, enc)
+ if e := enc.EncodeTime; e != nil {
+ e(val, enc)
+ }
if cur == enc.buf.Len() {
// User-supplied EncodeTime is a no-op. Fall back to nanos since epoch to keep
// output JSON valid.
@@ -343,14 +366,20 @@
final.AppendString(ent.LoggerName)
}
}
- if ent.Caller.Defined && final.CallerKey != "" {
- final.addKey(final.CallerKey)
- cur := final.buf.Len()
- final.EncodeCaller(ent.Caller, final)
- if cur == final.buf.Len() {
- // User-supplied EncodeCaller was a no-op. Fall back to strings to
- // keep output JSON valid.
- final.AppendString(ent.Caller.String())
+ if ent.Caller.Defined {
+ if final.CallerKey != "" {
+ final.addKey(final.CallerKey)
+ cur := final.buf.Len()
+ final.EncodeCaller(ent.Caller, final)
+ if cur == final.buf.Len() {
+ // User-supplied EncodeCaller was a no-op. Fall back to strings to
+ // keep output JSON valid.
+ final.AppendString(ent.Caller.String())
+ }
+ }
+ if final.FunctionKey != "" {
+ final.addKey(final.FunctionKey)
+ final.AppendString(ent.Caller.Function)
}
}
if final.MessageKey != "" {