diff --git a/example_test.go b/example_test.go index 42258aa06..28474d0cd 100644 --- a/example_test.go +++ b/example_test.go @@ -184,7 +184,7 @@ func (a addr) MarshalLogObject(enc zapcore.ObjectEncoder) error { func (r request) MarshalLogObject(enc zapcore.ObjectEncoder) error { enc.AddString("url", r.URL) - zap.InlineObject(r.Listen).AddTo(enc) + zap.Inline(r.Listen).AddTo(enc) return enc.AddObject("remote", r.Remote) } @@ -198,7 +198,7 @@ func ExampleObject() { Remote: addr{"127.0.0.1", 31200}, } logger.Info("new request, in nested object", zap.Object("req", req)) - logger.Info("new request, inline", zap.InlineObject(req)) + logger.Info("new request, inline", zap.Inline(req)) // Output: // {"level":"info","msg":"new request, in nested object","req":{"url":"/test","ip":"127.0.0.1","port":8080,"remote":{"ip":"127.0.0.1","port":31200}}} // {"level":"info","msg":"new request, inline","url":"/test","ip":"127.0.0.1","port":8080,"remote":{"ip":"127.0.0.1","port":31200}} diff --git a/field.go b/field.go index 02018a834..cc74deb87 100644 --- a/field.go +++ b/field.go @@ -400,11 +400,11 @@ func Object(key string, val zapcore.ObjectMarshaler) Field { return Field{Key: key, Type: zapcore.ObjectMarshalerType, Interface: val} } -// InlineObject is similar to Object, but does not nest the object under a field +// Inline is similar to Object, but does not nest the object under a field // name, but adds the fields to the current namespace inline. -func InlineObject(val zapcore.ObjectMarshaler) Field { +func Inline(val zapcore.ObjectMarshaler) Field { return zapcore.Field{ - Type: zapcore.InlineObjectMarshalerType, + Type: zapcore.InlineMarshalerType, Interface: val, } } diff --git a/field_test.go b/field_test.go index 0753874fb..010e6fb4d 100644 --- a/field_test.go +++ b/field_test.go @@ -123,7 +123,7 @@ func TestFieldConstructors(t *testing.T) { {"Reflect", Field{Key: "k", Type: zapcore.ReflectType}, Reflect("k", nil)}, {"Stringer", Field{Key: "k", Type: zapcore.StringerType, Interface: addr}, Stringer("k", addr)}, {"Object", Field{Key: "k", Type: zapcore.ObjectMarshalerType, Interface: name}, Object("k", name)}, - {"InlineObject", Field{Type: zapcore.InlineObjectMarshalerType, Interface: name}, InlineObject(name)}, + {"Inline", Field{Type: zapcore.InlineMarshalerType, Interface: name}, Inline(name)}, {"Any:ObjectMarshaler", Any("k", name), Object("k", name)}, {"Any:ArrayMarshaler", Any("k", bools([]bool{true})), Array("k", bools([]bool{true}))}, {"Any:Stringer", Any("k", addr), Stringer("k", addr)}, diff --git a/zapcore/field.go b/zapcore/field.go index b7799a4e0..29daaace9 100644 --- a/zapcore/field.go +++ b/zapcore/field.go @@ -39,9 +39,9 @@ const ( ArrayMarshalerType // ObjectMarshalerType indicates that the field carries an ObjectMarshaler. ObjectMarshalerType - // InlineObjectMarshalerType indicates that the field carries an ObjectMarshaler + // InlineMarshalerType indicates that the field carries an ObjectMarshaler // that should be inlined. - InlineObjectMarshalerType + InlineMarshalerType // BinaryType indicates that the field carries an opaque binary blob. BinaryType // BoolType indicates that the field carries a bool. @@ -118,7 +118,7 @@ func (f Field) AddTo(enc ObjectEncoder) { err = enc.AddArray(f.Key, f.Interface.(ArrayMarshaler)) case ObjectMarshalerType: err = enc.AddObject(f.Key, f.Interface.(ObjectMarshaler)) - case InlineObjectMarshalerType: + case InlineMarshalerType: err = f.Interface.(ObjectMarshaler).MarshalLogObject(enc) case BinaryType: enc.AddBinary(f.Key, f.Interface.([]byte)) diff --git a/zapcore/field_test.go b/zapcore/field_test.go index 60e158afd..c4363297c 100644 --- a/zapcore/field_test.go +++ b/zapcore/field_test.go @@ -111,7 +111,7 @@ func TestFieldAddingError(t *testing.T) { }{ {t: ArrayMarshalerType, iface: users(-1), want: []interface{}{}, err: "too few users"}, {t: ObjectMarshalerType, iface: users(-1), want: map[string]interface{}{}, err: "too few users"}, - {t: InlineObjectMarshalerType, iface: users(-1), want: nil, err: "too few users"}, + {t: InlineMarshalerType, iface: users(-1), want: nil, err: "too few users"}, {t: StringerType, iface: obj{}, want: empty, err: "PANIC=interface conversion: zapcore_test.obj is not fmt.Stringer: missing method String"}, {t: StringerType, iface: &obj{1}, want: empty, err: "PANIC=panic with string"}, {t: StringerType, iface: &obj{2}, want: empty, err: "PANIC=panic with error"}, @@ -180,13 +180,13 @@ func TestFields(t *testing.T) { } } -func TestInlineObjectMarshaler(t *testing.T) { +func TestInlineMarshaler(t *testing.T) { enc := NewMapObjectEncoder() topLevelStr := Field{Key: "k", Type: StringType, String: "s"} topLevelStr.AddTo(enc) - inlineObj := Field{Key: "ignored", Type: InlineObjectMarshalerType, Interface: users(10)} + inlineObj := Field{Key: "ignored", Type: InlineMarshalerType, Interface: users(10)} inlineObj.AddTo(enc) nestedObj := Field{Key: "nested", Type: ObjectMarshalerType, Interface: users(11)}