Rename Object to Interface

This commit is contained in:
Olivier Poitrey 2017-05-19 22:25:37 -07:00
parent 156a4e8b0f
commit 76d3c39327
4 changed files with 12 additions and 12 deletions

View File

@ -128,8 +128,8 @@ func (c Context) Time(key string, t time.Time) Context {
return c
}
// Object adds the field key with obj marshaled using reflection.
func (c Context) Object(key string, obj interface{}) Context {
c.l.context = appendObject(c.l.context, key, obj)
// Interface adds the field key with obj marshaled using reflection.
func (c Context) Interface(key string, i interface{}) Context {
c.l.context = appendInterface(c.l.context, key, i)
return c
}

View File

@ -262,11 +262,11 @@ func (e *Event) Time(key string, t time.Time) *Event {
return e
}
// Object adds the field key with obj marshaled using reflection.
func (e *Event) Object(key string, obj interface{}) *Event {
// Interface adds the field key with i marshaled using reflection.
func (e *Event) Interface(key string, i interface{}) *Event {
if !e.enabled {
return e
}
e.buf = appendObject(e.buf, key, obj)
e.buf = appendInterface(e.buf, key, i)
return e
}

View File

@ -88,8 +88,8 @@ func appendTimestamp(dst []byte) []byte {
return appendTime(dst, TimestampFieldName, now())
}
func appendObject(dst []byte, key string, obj interface{}) []byte {
marshaled, err := json.Marshal(obj)
func appendInterface(dst []byte, key string, i interface{}) []byte {
marshaled, err := json.Marshal(i)
if err != nil {
return appendString(dst, key, fmt.Sprintf("marshaling error: %v", err))
}

View File

@ -114,7 +114,7 @@ func ExampleEvent_Dict() {
// Output: {"foo":"bar","dict":{"bar":"baz","n":1},"message":"hello world"}
}
func ExampleEvent_Object() {
func ExampleEvent_Interface() {
log := zerolog.New(os.Stdout)
obj := struct {
@ -125,7 +125,7 @@ func ExampleEvent_Object() {
log.Log().
Str("foo", "bar").
Object("obj", obj).
Interface("obj", obj).
Msg("hello world")
// Output: {"foo":"bar","obj":{"name":"john"},"message":"hello world"}
@ -144,7 +144,7 @@ func ExampleContext_Dict() {
// Output: {"foo":"bar","dict":{"bar":"baz","n":1},"message":"hello world"}
}
func ExampleContext_Object() {
func ExampleContext_Interface() {
obj := struct {
Name string `json:"name"`
}{
@ -153,7 +153,7 @@ func ExampleContext_Object() {
log := zerolog.New(os.Stdout).With().
Str("foo", "bar").
Object("obj", obj).
Interface("obj", obj).
Logger()
log.Log().Msg("hello world")