From 9e5bc0d3eae3952554d5dc91edd6bace8a17497c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mike=20Schw=C3=B6rer?= Date: Tue, 22 Aug 2023 10:36:35 +0200 Subject: [PATCH] v0.0.253 --- exerr/exerr.go | 16 ++++++++++++++++ ginext/response.go | 2 +- goextVersion.go | 4 ++-- 3 files changed, 19 insertions(+), 3 deletions(-) diff --git a/exerr/exerr.go b/exerr/exerr.go index a6dd2e6..c9e209b 100644 --- a/exerr/exerr.go +++ b/exerr/exerr.go @@ -4,7 +4,10 @@ import ( "github.com/rs/xid" "github.com/rs/zerolog" "gogs.mikescher.com/BlackForestBytes/goext/langext" + "gogs.mikescher.com/BlackForestBytes/goext/rext" "reflect" + "regexp" + "strconv" "strings" "time" ) @@ -77,7 +80,10 @@ func (ee *ExErr) As(target any) bool { } func (ee *ExErr) Log(evt *zerolog.Event) { + backup := zerolog.CallerMarshalFunc + zerolog.CallerMarshalFunc = customZerologCallerMarshalFunc evt.Msg(ee.FormatLog(LogPrintFull)) + zerolog.CallerMarshalFunc = backup } func (ee *ExErr) FormatLog(lvl LogPrintLevel) string { @@ -164,7 +170,10 @@ func (ee *ExErr) FormatLog(lvl LogPrintLevel) string { } func (ee *ExErr) ShortLog(evt *zerolog.Event) { + backup := zerolog.CallerMarshalFunc + zerolog.CallerMarshalFunc = customZerologCallerMarshalFunc ee.Meta.Apply(evt).Msg(ee.FormatLog(LogPrintShort)) + zerolog.CallerMarshalFunc = backup } // RecursiveMessage returns the message to show @@ -296,3 +305,10 @@ func (ee *ExErr) equalsDirectProperties(other *ExErr) bool { func newID() string { return xid.New().String() } + +var regexZerologCallerClean = rext.W(regexp.MustCompile(`^(\.\./)*/?go/pkg/mod/gogs\.(mikescher|blackforestbytes)\.(com|de)/!black!forest!bytes/?`)) + +func customZerologCallerMarshalFunc(pc uintptr, file string, line int) string { + file = regexZerologCallerClean.ReplaceAll(file, "", true) + return file + ":" + strconv.Itoa(line) +} diff --git a/ginext/response.go b/ginext/response.go index 7c12607..eafe6e4 100644 --- a/ginext/response.go +++ b/ginext/response.go @@ -207,7 +207,7 @@ func Error(e error) HTTPResponse { func ErrWrap(e error, errorType exerr.ErrorType, msg string) HTTPResponse { return &jsonAPIErrResponse{ - err: exerr.FromError(exerr.Wrap(e, msg).WithStackSkip(3).WithType(errorType).Build()), + err: exerr.FromError(exerr.Wrap(e, msg).WithType(errorType).Build()), } } diff --git a/goextVersion.go b/goextVersion.go index c59ab28..323ad6d 100644 --- a/goextVersion.go +++ b/goextVersion.go @@ -1,5 +1,5 @@ package goext -const GoextVersion = "0.0.252" +const GoextVersion = "0.0.253" -const GoextVersionTimestamp = "2023-08-22T10:23:04+0200" +const GoextVersionTimestamp = "2023-08-22T10:36:35+0200"