diff --git a/field.go b/field.go index 27be5c726..c8ff1372a 100644 --- a/field.go +++ b/field.go @@ -224,6 +224,10 @@ func Object(key string, val zapcore.ObjectMarshaler) zapcore.Field { // Any takes a key and an arbitrary value and chooses the best way to represent // them as a field, falling back to a reflection-based approach only if // necessary. +// +// Since byte/uint8 and rune/int32 are aliases, Any can't differentiate between +// them. To minimize suprise, []byte values are treated as binary blobs, byte +// values are treated as uint8, and runes are always treated as integers. func Any(key string, value interface{}) zapcore.Field { switch val := value.(type) { case zapcore.ObjectMarshaler: @@ -292,8 +296,8 @@ func Any(key string, value interface{}) zapcore.Field { return Uint16s(key, val) case uint8: return Uint8(key, val) - case []uint8: - return Uint8s(key, val) + case []byte: + return Binary(key, val) case uintptr: return Uintptr(key, val) case []uintptr: diff --git a/field_test.go b/field_test.go index 6de2bd431..7c1a1295f 100644 --- a/field_test.go +++ b/field_test.go @@ -112,7 +112,7 @@ func TestFieldConstructors(t *testing.T) { {"Any:Bool", Any("k", true), Bool("k", true)}, {"Any:Bools", Any("k", []bool{true}), Bools("k", []bool{true})}, {"Any:Byte", Any("k", byte(1)), Uint8("k", 1)}, - {"Any:Bytes", Any("k", []byte{1}), Uint8s("k", []uint8{1})}, + {"Any:Bytes", Any("k", []byte{1}), Binary("k", []byte{1})}, {"Any:Complex128", Any("k", 1+2i), Complex128("k", 1+2i)}, {"Any:Complex128s", Any("k", []complex128{1 + 2i}), Complex128s("k", []complex128{1 + 2i})}, {"Any:Complex64", Any("k", complex64(1+2i)), Complex64("k", 1+2i)}, @@ -144,7 +144,7 @@ func TestFieldConstructors(t *testing.T) { {"Any:Uint16", Any("k", uint16(1)), Uint16("k", 1)}, {"Any:Uint16s", Any("k", []uint16{1}), Uint16s("k", []uint16{1})}, {"Any:Uint8", Any("k", uint8(1)), Uint8("k", 1)}, - {"Any:Uint8s", Any("k", []uint8{1}), Uint8s("k", []uint8{1})}, + {"Any:Uint8s", Any("k", []uint8{1}), Binary("k", []uint8{1})}, {"Any:Uintptr", Any("k", uintptr(1)), Uintptr("k", 1)}, {"Any:Uintptrs", Any("k", []uintptr{1}), Uintptrs("k", []uintptr{1})}, {"Any:Time", Any("k", time.Unix(0, 0)), Time("k", time.Unix(0, 0))},