v0.0.274 limit exerr log meta values (shortlog) to 240 chars
All checks were successful
Build Docker and Deploy / Run goext test-suite (push) Successful in 50s

This commit is contained in:
Mike Schwörer 2023-09-27 16:18:21 +02:00
parent 08681756b6
commit 7577a2dd47
Signed by: Mikescher
GPG Key ID: D3C7172E0A70F8CF
3 changed files with 21 additions and 9 deletions

View File

@ -164,7 +164,7 @@ func (ee *ExErr) FormatLog(lvl LogPrintLevel) string {
}
func (ee *ExErr) ShortLog(evt *zerolog.Event) {
ee.Meta.Apply(evt).Msg(ee.FormatLog(LogPrintShort))
ee.Meta.Apply(evt, langext.Ptr(240)).Msg(ee.FormatLog(LogPrintShort))
}
// RecursiveMessage returns the message to show

View File

@ -217,23 +217,35 @@ func (v MetaValue) ShortString(lim int) string {
return "(err)"
}
func (v MetaValue) Apply(key string, evt *zerolog.Event) *zerolog.Event {
func (v MetaValue) Apply(key string, evt *zerolog.Event, limitLen *int) *zerolog.Event {
switch v.DataType {
case MDTString:
return evt.Str(key, v.Value.(string))
if limitLen == nil {
return evt.Str(key, v.Value.(string))
} else {
evt.Str(key, langext.StrLimit(v.Value.(string), *limitLen, "..."))
}
case MDTID:
return evt.Str(key, v.Value.(IDWrap).Value)
case MDTAny:
if v.Value.(AnyWrap).IsError {
return evt.Str(key, "(err)")
} else {
return evt.Str(key, v.Value.(AnyWrap).Json)
if limitLen == nil {
return evt.Str(key, v.Value.(AnyWrap).Json)
} else {
evt.Str(key, langext.StrLimit(v.Value.(AnyWrap).Json, *limitLen, "..."))
}
}
case MDTStringPtr:
if langext.IsNil(v.Value) {
return evt.Str(key, "<<null>>")
}
return evt.Str(key, langext.CoalesceString(v.Value.(*string), "<<null>>"))
if limitLen == nil {
return evt.Str(key, langext.CoalesceString(v.Value.(*string), "<<null>>"))
} else {
evt.Str(key, langext.StrLimit(langext.CoalesceString(v.Value.(*string), "<<null>>"), *limitLen, "..."))
}
case MDTInt:
return evt.Int(key, v.Value.(int))
case MDTInt8:
@ -702,9 +714,9 @@ func (mm MetaMap) Any() bool {
return len(mm) > 0
}
func (mm MetaMap) Apply(evt *zerolog.Event) *zerolog.Event {
func (mm MetaMap) Apply(evt *zerolog.Event, limitLen *int) *zerolog.Event {
for key, val := range mm {
evt = val.Apply(key, evt)
evt = val.Apply(key, evt, limitLen)
}
return evt
}

View File

@ -1,5 +1,5 @@
package goext
const GoextVersion = "0.0.273"
const GoextVersion = "0.0.274"
const GoextVersionTimestamp = "2023-09-27T14:15:59+0200"
const GoextVersionTimestamp = "2023-09-27T16:18:21+0200"