Merge pull request #179 from unistack-org/logger-unwrap
logger/unwrap: fix unwrap format
This commit is contained in:
commit
848fe1c0d4
@ -353,6 +353,7 @@ func (f *unwrap) format(v reflect.Value) {
|
|||||||
f.depth++
|
f.depth++
|
||||||
vt := v.Type()
|
vt := v.Type()
|
||||||
prevSkip := false
|
prevSkip := false
|
||||||
|
|
||||||
for i := 0; i < numFields; i++ {
|
for i := 0; i < numFields; i++ {
|
||||||
sv, ok := vt.Field(i).Tag.Lookup("logger")
|
sv, ok := vt.Field(i).Tag.Lookup("logger")
|
||||||
if ok {
|
if ok {
|
||||||
@ -367,13 +368,16 @@ func (f *unwrap) format(v reflect.Value) {
|
|||||||
prevSkip = true
|
prevSkip = true
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if i > 0 && !prevSkip {
|
|
||||||
_, _ = f.s.Write(commaBytes)
|
|
||||||
_, _ = f.s.Write(spaceBytes)
|
|
||||||
}
|
|
||||||
if prevSkip {
|
if prevSkip {
|
||||||
prevSkip = false
|
prevSkip = false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if numWritten > 0 {
|
||||||
|
_, _ = f.s.Write(commaBytes)
|
||||||
|
_, _ = f.s.Write(spaceBytes)
|
||||||
|
}
|
||||||
|
|
||||||
vtf := vt.Field(i)
|
vtf := vt.Field(i)
|
||||||
if f.s.Flag('+') || f.s.Flag('#') {
|
if f.s.Flag('+') || f.s.Flag('#') {
|
||||||
_, _ = f.s.Write([]byte(vtf.Name))
|
_, _ = f.s.Write([]byte(vtf.Name))
|
||||||
|
@ -86,12 +86,12 @@ func TestTaggedNested(t *testing.T) {
|
|||||||
unk string
|
unk string
|
||||||
}
|
}
|
||||||
type str struct {
|
type str struct {
|
||||||
val *val `logger:"take"`
|
|
||||||
key string `logger:"omit"`
|
key string `logger:"omit"`
|
||||||
|
val *val `logger:"take"`
|
||||||
}
|
}
|
||||||
|
|
||||||
var iface interface{}
|
var iface interface{}
|
||||||
v := &str{key: "omit", val: &val{key: "test", val: "omit", unk: "unk"}}
|
v := &str{val: &val{key: "test", unk: "unk"}}
|
||||||
iface = v
|
iface = v
|
||||||
buf := fmt.Sprintf("%#v", Unwrap(iface, Tagged(true)))
|
buf := fmt.Sprintf("%#v", Unwrap(iface, Tagged(true)))
|
||||||
if strings.Compare(buf, `&unwrap.str{val:(*unwrap.val){key:"test"}}`) != 0 {
|
if strings.Compare(buf, `&unwrap.str{val:(*unwrap.val){key:"test"}}`) != 0 {
|
||||||
|
Loading…
Reference in New Issue
Block a user