1package zap_cli_encoder 2 3import ( 4 "fmt" 5 "time" 6 7 "go.uber.org/zap/buffer" 8 "go.uber.org/zap/zapcore" 9) 10 11type bufferArrayEncoder struct { 12 buffer *buffer.Buffer 13} 14 15func (t *bufferArrayEncoder) AppendComplex128(v complex128) { 16 r, i := real(v), imag(v) 17 t.buffer.AppendFloat(r, 64) 18 t.buffer.AppendByte('+') 19 t.buffer.AppendFloat(i, 64) 20 t.buffer.AppendByte('i') 21} 22 23func (t *bufferArrayEncoder) AppendComplex64(v complex64) { 24 //noinspection GoRedundantConversion 25 t.AppendComplex128(complex128(v)) 26} 27 28func (t *bufferArrayEncoder) AppendArray(v zapcore.ArrayMarshaler) error { 29 enc := &bufferArrayEncoder{} 30 err := v.MarshalLogArray(enc) 31 _, _ = fmt.Fprintf(t.buffer, "%v", enc.buffer) 32 return err 33} 34 35func (t *bufferArrayEncoder) AppendObject(v zapcore.ObjectMarshaler) error { 36 m := zapcore.NewMapObjectEncoder() 37 err := v.MarshalLogObject(m) 38 _, _ = fmt.Fprintf(t.buffer, "%v", m.Fields) 39 return err 40} 41 42func (t *bufferArrayEncoder) AppendReflected(v interface{}) error { 43 _, _ = fmt.Fprintf(t.buffer, "%v", v) 44 return nil 45} 46 47func (t *bufferArrayEncoder) AppendBool(v bool) { 48 t.buffer.AppendBool(v) 49} 50 51func (t *bufferArrayEncoder) AppendByteString(v []byte) { 52 t.buffer.AppendString(string(v)) 53} 54 55func (t *bufferArrayEncoder) AppendDuration(v time.Duration) { 56 t.AppendString(v.String()) 57} 58 59func (t *bufferArrayEncoder) AppendFloat64(v float64) { t.buffer.AppendFloat(v, 64) } 60func (t *bufferArrayEncoder) AppendFloat32(v float32) { t.buffer.AppendFloat(float64(v), 32) } 61func (t *bufferArrayEncoder) AppendInt(v int) { t.buffer.AppendInt(int64(v)) } 62func (t *bufferArrayEncoder) AppendInt64(v int64) { t.buffer.AppendInt(v) } 63func (t *bufferArrayEncoder) AppendInt32(v int32) { t.buffer.AppendInt(int64(v)) } 64func (t *bufferArrayEncoder) AppendInt16(v int16) { t.buffer.AppendInt(int64(v)) } 65func (t *bufferArrayEncoder) AppendInt8(v int8) { t.buffer.AppendInt(int64(v)) } 66func (t *bufferArrayEncoder) AppendString(v string) { t.buffer.AppendString(v) } 67func (t *bufferArrayEncoder) AppendTime(v time.Time) { t.buffer.AppendString(v.String()) } 68func (t *bufferArrayEncoder) AppendUint(v uint) { t.buffer.AppendUint(uint64(v)) } 69func (t *bufferArrayEncoder) AppendUint64(v uint64) { t.buffer.AppendUint(v) } 70func (t *bufferArrayEncoder) AppendUint32(v uint32) { t.buffer.AppendUint(uint64(v)) } 71func (t *bufferArrayEncoder) AppendUint16(v uint16) { t.buffer.AppendUint(uint64(v)) } 72func (t *bufferArrayEncoder) AppendUint8(v uint8) { t.buffer.AppendUint(uint64(v)) } 73func (t *bufferArrayEncoder) AppendUintptr(v uintptr) { t.buffer.AppendUint(uint64(v)) } 74