parent
24cc441b11
commit
d0ca9bbceb
32
fields.go
32
fields.go
|
@ -54,6 +54,38 @@ func appendFields(dst []byte, fields map[string]interface{}) []byte {
|
|||
dst = json.AppendTime(dst, val, TimeFieldFormat)
|
||||
case time.Duration:
|
||||
dst = json.AppendDuration(dst, val, DurationFieldUnit, DurationFieldInteger)
|
||||
case *string:
|
||||
dst = json.AppendString(dst, *val)
|
||||
case *bool:
|
||||
dst = json.AppendBool(dst, *val)
|
||||
case *int:
|
||||
dst = json.AppendInt(dst, *val)
|
||||
case *int8:
|
||||
dst = json.AppendInt8(dst, *val)
|
||||
case *int16:
|
||||
dst = json.AppendInt16(dst, *val)
|
||||
case *int32:
|
||||
dst = json.AppendInt32(dst, *val)
|
||||
case *int64:
|
||||
dst = json.AppendInt64(dst, *val)
|
||||
case *uint:
|
||||
dst = json.AppendUint(dst, *val)
|
||||
case *uint8:
|
||||
dst = json.AppendUint8(dst, *val)
|
||||
case *uint16:
|
||||
dst = json.AppendUint16(dst, *val)
|
||||
case *uint32:
|
||||
dst = json.AppendUint32(dst, *val)
|
||||
case *uint64:
|
||||
dst = json.AppendUint64(dst, *val)
|
||||
case *float32:
|
||||
dst = json.AppendFloat32(dst, *val)
|
||||
case *float64:
|
||||
dst = json.AppendFloat64(dst, *val)
|
||||
case *time.Time:
|
||||
dst = json.AppendTime(dst, *val, TimeFieldFormat)
|
||||
case *time.Duration:
|
||||
dst = json.AppendDuration(dst, *val, DurationFieldUnit, DurationFieldInteger)
|
||||
case []string:
|
||||
dst = json.AppendStrings(dst, val)
|
||||
case []bool:
|
||||
|
|
26
log_test.go
26
log_test.go
|
@ -135,6 +135,32 @@ func TestFieldsMap(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func TestFieldsMapPnt(t *testing.T) {
|
||||
out := &bytes.Buffer{}
|
||||
log := New(out)
|
||||
log.Log().Fields(map[string]interface{}{
|
||||
"string": new(string),
|
||||
"bool": new(bool),
|
||||
"int": new(int),
|
||||
"int8": new(int8),
|
||||
"int16": new(int16),
|
||||
"int32": new(int32),
|
||||
"int64": new(int64),
|
||||
"uint": new(uint),
|
||||
"uint8": new(uint8),
|
||||
"uint16": new(uint16),
|
||||
"uint32": new(uint32),
|
||||
"uint64": new(uint64),
|
||||
"float32": new(float32),
|
||||
"float64": new(float64),
|
||||
"dur": new(time.Duration),
|
||||
"time": new(time.Time),
|
||||
}).Msg("")
|
||||
if got, want := out.String(), `{"bool":false,"dur":0,"float32":0,"float64":0,"int":0,"int16":0,"int32":0,"int64":0,"int8":0,"string":"","time":"0001-01-01T00:00:00Z","uint":0,"uint16":0,"uint32":0,"uint64":0,"uint8":0}`+"\n"; got != want {
|
||||
t.Errorf("invalid log output:\ngot: %v\nwant: %v", got, want)
|
||||
}
|
||||
}
|
||||
|
||||
func TestFields(t *testing.T) {
|
||||
out := &bytes.Buffer{}
|
||||
log := New(out)
|
||||
|
|
Loading…
Reference in New Issue