Rename Object to Interface
This commit is contained in:
parent
156a4e8b0f
commit
76d3c39327
|
@ -128,8 +128,8 @@ func (c Context) Time(key string, t time.Time) Context {
|
||||||
return c
|
return c
|
||||||
}
|
}
|
||||||
|
|
||||||
// Object adds the field key with obj marshaled using reflection.
|
// Interface adds the field key with obj marshaled using reflection.
|
||||||
func (c Context) Object(key string, obj interface{}) Context {
|
func (c Context) Interface(key string, i interface{}) Context {
|
||||||
c.l.context = appendObject(c.l.context, key, obj)
|
c.l.context = appendInterface(c.l.context, key, i)
|
||||||
return c
|
return c
|
||||||
}
|
}
|
||||||
|
|
6
event.go
6
event.go
|
@ -262,11 +262,11 @@ func (e *Event) Time(key string, t time.Time) *Event {
|
||||||
return e
|
return e
|
||||||
}
|
}
|
||||||
|
|
||||||
// Object adds the field key with obj marshaled using reflection.
|
// Interface adds the field key with i marshaled using reflection.
|
||||||
func (e *Event) Object(key string, obj interface{}) *Event {
|
func (e *Event) Interface(key string, i interface{}) *Event {
|
||||||
if !e.enabled {
|
if !e.enabled {
|
||||||
return e
|
return e
|
||||||
}
|
}
|
||||||
e.buf = appendObject(e.buf, key, obj)
|
e.buf = appendInterface(e.buf, key, i)
|
||||||
return e
|
return e
|
||||||
}
|
}
|
||||||
|
|
4
field.go
4
field.go
|
@ -88,8 +88,8 @@ func appendTimestamp(dst []byte) []byte {
|
||||||
return appendTime(dst, TimestampFieldName, now())
|
return appendTime(dst, TimestampFieldName, now())
|
||||||
}
|
}
|
||||||
|
|
||||||
func appendObject(dst []byte, key string, obj interface{}) []byte {
|
func appendInterface(dst []byte, key string, i interface{}) []byte {
|
||||||
marshaled, err := json.Marshal(obj)
|
marshaled, err := json.Marshal(i)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return appendString(dst, key, fmt.Sprintf("marshaling error: %v", err))
|
return appendString(dst, key, fmt.Sprintf("marshaling error: %v", err))
|
||||||
}
|
}
|
||||||
|
|
|
@ -114,7 +114,7 @@ func ExampleEvent_Dict() {
|
||||||
// Output: {"foo":"bar","dict":{"bar":"baz","n":1},"message":"hello world"}
|
// Output: {"foo":"bar","dict":{"bar":"baz","n":1},"message":"hello world"}
|
||||||
}
|
}
|
||||||
|
|
||||||
func ExampleEvent_Object() {
|
func ExampleEvent_Interface() {
|
||||||
log := zerolog.New(os.Stdout)
|
log := zerolog.New(os.Stdout)
|
||||||
|
|
||||||
obj := struct {
|
obj := struct {
|
||||||
|
@ -125,7 +125,7 @@ func ExampleEvent_Object() {
|
||||||
|
|
||||||
log.Log().
|
log.Log().
|
||||||
Str("foo", "bar").
|
Str("foo", "bar").
|
||||||
Object("obj", obj).
|
Interface("obj", obj).
|
||||||
Msg("hello world")
|
Msg("hello world")
|
||||||
|
|
||||||
// Output: {"foo":"bar","obj":{"name":"john"},"message":"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"}
|
// Output: {"foo":"bar","dict":{"bar":"baz","n":1},"message":"hello world"}
|
||||||
}
|
}
|
||||||
|
|
||||||
func ExampleContext_Object() {
|
func ExampleContext_Interface() {
|
||||||
obj := struct {
|
obj := struct {
|
||||||
Name string `json:"name"`
|
Name string `json:"name"`
|
||||||
}{
|
}{
|
||||||
|
@ -153,7 +153,7 @@ func ExampleContext_Object() {
|
||||||
|
|
||||||
log := zerolog.New(os.Stdout).With().
|
log := zerolog.New(os.Stdout).With().
|
||||||
Str("foo", "bar").
|
Str("foo", "bar").
|
||||||
Object("obj", obj).
|
Interface("obj", obj).
|
||||||
Logger()
|
Logger()
|
||||||
|
|
||||||
log.Log().Msg("hello world")
|
log.Log().Msg("hello world")
|
||||||
|
|
Loading…
Reference in New Issue