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
All checks were successful
Build Docker and Deploy / Run goext test-suite (push) Successful in 2m29s
This commit is contained in:
parent
a0dc9e92e4
commit
073aa84dd4
@ -5,12 +5,12 @@ import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"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/enums"
|
||||
"git.blackforestbytes.com/BlackForestBytes/goext/langext"
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/rs/zerolog"
|
||||
"go.mongodb.org/mongo-driver/bson/primitive"
|
||||
"net/http"
|
||||
"os"
|
||||
"runtime/debug"
|
||||
@ -445,6 +445,8 @@ func (b *Builder) BuildAsExerr(ctxs ...context.Context) *ExErr {
|
||||
// The error also gets printed to stdout/stderr
|
||||
// If the error is SevErr|SevFatal we also send it to the error-service
|
||||
func (b *Builder) Output(ctx context.Context, g *gin.Context) {
|
||||
warnOnPkgConfigNotInitialized()
|
||||
|
||||
if !b.containsGinData && g.Request != nil {
|
||||
// Auto-Add gin metadata if the caller hasn't already done it
|
||||
b.GinReq(ctx, g, g.Request)
|
||||
@ -452,6 +454,12 @@ func (b *Builder) Output(ctx context.Context, g *gin.Context) {
|
||||
|
||||
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)
|
||||
|
||||
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)
|
||||
}
|
||||
|
||||
// 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 {
|
||||
b.errorData.Log(pkgconfig.ZeroLogger.Error())
|
||||
} else if b.errorData.Severity == SevWarn {
|
||||
@ -501,13 +515,19 @@ func (b *Builder) Fatal(ctxs ...context.Context) {
|
||||
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})
|
||||
|
||||
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 {
|
||||
|
@ -3,9 +3,9 @@ package exerr
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"git.blackforestbytes.com/BlackForestBytes/goext/langext"
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/rs/zerolog"
|
||||
"git.blackforestbytes.com/BlackForestBytes/goext/langext"
|
||||
"net/http"
|
||||
"os"
|
||||
)
|
||||
@ -119,7 +119,7 @@ func newDefaultLogger() zerolog.Logger {
|
||||
|
||||
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 {
|
||||
|
@ -1,5 +1,5 @@
|
||||
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"
|
||||
|
Loading…
x
Reference in New Issue
Block a user