From 7577a2dd4733853a518a66c5ac77954242128c92 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mike=20Schw=C3=B6rer?= Date: Wed, 27 Sep 2023 16:18:21 +0200 Subject: [PATCH] v0.0.274 limit exerr log meta values (shortlog) to 240 chars --- exerr/exerr.go | 2 +- exerr/meta.go | 24 ++++++++++++++++++------ goextVersion.go | 4 ++-- 3 files changed, 21 insertions(+), 9 deletions(-) diff --git a/exerr/exerr.go b/exerr/exerr.go index a6dd2e6..b303f85 100644 --- a/exerr/exerr.go +++ b/exerr/exerr.go @@ -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 diff --git a/exerr/meta.go b/exerr/meta.go index 81bfa45..f2c6574 100644 --- a/exerr/meta.go +++ b/exerr/meta.go @@ -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, "<>") } - return evt.Str(key, langext.CoalesceString(v.Value.(*string), "<>")) + if limitLen == nil { + return evt.Str(key, langext.CoalesceString(v.Value.(*string), "<>")) + } else { + evt.Str(key, langext.StrLimit(langext.CoalesceString(v.Value.(*string), "<>"), *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 } diff --git a/goextVersion.go b/goextVersion.go index 949083f..f7406bf 100644 --- a/goextVersion.go +++ b/goextVersion.go @@ -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"