v0.0.579 fix StackSkip count on exerr zero-logger for Build()
All checks were successful
Build Docker and Deploy / Run goext test-suite (push) Successful in 2m29s

This commit is contained in:
Mike Schwörer 2025-06-13 16:53:24 +02:00
parent a0dc9e92e4
commit 073aa84dd4
Signed by: Mikescher
GPG Key ID: D3C7172E0A70F8CF
3 changed files with 28 additions and 8 deletions

View File

@ -5,12 +5,12 @@ import (
"context" "context"
"encoding/json" "encoding/json"
"fmt" "fmt"
"github.com/gin-gonic/gin"
"github.com/rs/zerolog"
"go.mongodb.org/mongo-driver/bson/primitive"
"git.blackforestbytes.com/BlackForestBytes/goext/dataext" "git.blackforestbytes.com/BlackForestBytes/goext/dataext"
"git.blackforestbytes.com/BlackForestBytes/goext/enums" "git.blackforestbytes.com/BlackForestBytes/goext/enums"
"git.blackforestbytes.com/BlackForestBytes/goext/langext" "git.blackforestbytes.com/BlackForestBytes/goext/langext"
"github.com/gin-gonic/gin"
"github.com/rs/zerolog"
"go.mongodb.org/mongo-driver/bson/primitive"
"net/http" "net/http"
"os" "os"
"runtime/debug" "runtime/debug"
@ -445,6 +445,8 @@ func (b *Builder) BuildAsExerr(ctxs ...context.Context) *ExErr {
// The error also gets printed to stdout/stderr // The error also gets printed to stdout/stderr
// If the error is SevErr|SevFatal we also send it to the error-service // If the error is SevErr|SevFatal we also send it to the error-service
func (b *Builder) Output(ctx context.Context, g *gin.Context) { func (b *Builder) Output(ctx context.Context, g *gin.Context) {
warnOnPkgConfigNotInitialized()
if !b.containsGinData && g.Request != nil { if !b.containsGinData && g.Request != nil {
// Auto-Add gin metadata if the caller hasn't already done it // Auto-Add gin metadata if the caller hasn't already done it
b.GinReq(ctx, g, g.Request) b.GinReq(ctx, g, g.Request)
@ -452,6 +454,12 @@ func (b *Builder) Output(ctx context.Context, g *gin.Context) {
b.CtxData(MethodOutput, ctx) b.CtxData(MethodOutput, ctx)
// this is only here to add one level to the trace
// so that .Build() and .Output() and .Print() have the same depth and our stack-skip logger can have the same skip-count
b.doOutput(ctx, g)
}
func (b *Builder) doOutput(ctx context.Context, g *gin.Context) {
b.errorData.Output(g) b.errorData.Output(g)
if (b.errorData.Severity == SevErr || b.errorData.Severity == SevFatal) && (pkgconfig.ZeroLogErrGinOutput || pkgconfig.ZeroLogAllGinOutput) { if (b.errorData.Severity == SevErr || b.errorData.Severity == SevFatal) && (pkgconfig.ZeroLogErrGinOutput || pkgconfig.ZeroLogAllGinOutput) {
@ -472,6 +480,12 @@ func (b *Builder) Print(ctxs ...context.Context) Proxy {
b.CtxData(MethodPrint, dctx) b.CtxData(MethodPrint, dctx)
} }
// this is only here to add one level to the trace
// so that .Build() and .Output() and .Print() have the same depth and our stack-skip logger can have the same skip-count
return b.doPrint()
}
func (b *Builder) doPrint() Proxy {
if b.errorData.Severity == SevErr || b.errorData.Severity == SevFatal { if b.errorData.Severity == SevErr || b.errorData.Severity == SevFatal {
b.errorData.Log(pkgconfig.ZeroLogger.Error()) b.errorData.Log(pkgconfig.ZeroLogger.Error())
} else if b.errorData.Severity == SevWarn { } else if b.errorData.Severity == SevWarn {
@ -501,13 +515,19 @@ func (b *Builder) Fatal(ctxs ...context.Context) {
b.CtxData(MethodFatal, dctx) b.CtxData(MethodFatal, dctx)
} }
b.errorData.Log(pkgconfig.ZeroLogger.WithLevel(zerolog.FatalLevel)) // this is only here to add one level to the trace
// so that .Build() and .Output() and .Print() have the same depth and our stack-skip logger can have the same skip-count
b.doLogFatal()
b.errorData.CallListener(MethodFatal, ListenerOpt{NoLog: b.noLog}) b.errorData.CallListener(MethodFatal, ListenerOpt{NoLog: b.noLog})
os.Exit(1) os.Exit(1)
} }
func (b *Builder) doLogFatal() {
b.errorData.Log(pkgconfig.ZeroLogger.WithLevel(zerolog.FatalLevel))
}
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
func (b *Builder) addMeta(key string, mdtype metaDataType, val interface{}) *Builder { func (b *Builder) addMeta(key string, mdtype metaDataType, val interface{}) *Builder {

View File

@ -3,9 +3,9 @@ package exerr
import ( import (
"context" "context"
"fmt" "fmt"
"git.blackforestbytes.com/BlackForestBytes/goext/langext"
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
"github.com/rs/zerolog" "github.com/rs/zerolog"
"git.blackforestbytes.com/BlackForestBytes/goext/langext"
"net/http" "net/http"
"os" "os"
) )
@ -119,7 +119,7 @@ func newDefaultLogger() zerolog.Logger {
multi := zerolog.MultiLevelWriter(cw) multi := zerolog.MultiLevelWriter(cw)
return zerolog.New(multi).With().Timestamp().CallerWithSkipFrameCount(4).Logger() return zerolog.New(multi).With().Timestamp().CallerWithSkipFrameCount(5).Logger()
} }
func Initialized() bool { func Initialized() bool {

View File

@ -1,5 +1,5 @@
package goext package goext
const GoextVersion = "0.0.578" const GoextVersion = "0.0.579"
const GoextVersionTimestamp = "2025-06-11T14:37:51+0200" const GoextVersionTimestamp = "2025-06-13T16:53:24+0200"