You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I've been trying otelzap as a wrapper for zap.
I've also created a thin wrapper to make logger usage more simplified across my packages:
package log
import (
"context""github.com/uptrace/opentelemetry-go-extra/otelzap""go.uber.org/zap"
)
// std is the name of the standard logger in stdlib `log`varstd*otelzap.LoggerfuncNew() *otelzap.Logger {
logger:=otelzap.New(zap.L(),
otelzap.WithTraceIDField(true),
otelzap.WithMinLevel(zap.DebugLevel))
std=loggerreturnlogger
}
funcL(ctx...context.Context) *otelzap.LoggerWithCtx {
varc context.Contextiflen(ctx) >0 {
c=ctx[0]
}
returnWithCtx(c)
}
funcS(ctx...context.Context) *otelzap.SugaredLoggerWithCtx {
varc context.Contextiflen(ctx) >0 {
c=ctx[0]
}
returnSugaredWithCtx(c)
}
funcWithCtx(ctx context.Context) *otelzap.LoggerWithCtx {
ctxl:=std.Ctx(ctx)
return&ctxl
}
funcSugaredWithCtx(ctx context.Context) *otelzap.SugaredLoggerWithCtx {
ctxl:=std.Sugar().Ctx(ctx)
return&ctxl
}
The plan is importing my log wrapper instead of zap (easy migration)
However, there are methods missing from SugaredLogger that do exist on zap.
.Info()
.Fatal()
.Debug()
.Error()
...
(the ones without formatting)
were there a reason why you didnt add them?
Im guessing it should look like:
// Info uses fmt.Sprint to construct and log a message.func (sSugaredLoggerWithCtx) Info(msgstring) {
s.s.logArgs(s.ctx, zap.InfoLevel, msg, nil)
s.s.Info(msg)
}
Should I go ahead and implement those for all levels?
Cheers 🥂
The text was updated successfully, but these errors were encountered:
// Info uses fmt.Sprint to construct and log a message.func (s*SugaredLogger) Info(args...interface{}) {
s.log(InfoLevel, "", args, nil)
}
Such logs are not structured and back-ends will have troubles parsing and grouping them. I guess we should support them, but such logs are neither efficient/fast nor structured so it is strange that Zap supports them...
Should I go ahead and implement those for all levels?
Yes, please.
I've also created a thin wrapper to make logger usage more simplified across my packages:
That looks good. otelzap already supports otelzap.L, otelzap.S, and otelzap.ReplaceGlobals. I guess we should also add otelzap.Ctx shortcut with some docs.
SugaredWithCtx is not much better than otelzap.S().Ctx(ctx) so I would leave it alone...
Hey,
I've been trying otelzap as a wrapper for zap.
I've also created a thin wrapper to make logger usage more simplified across my packages:
The plan is importing my log wrapper instead of zap (easy migration)
However, there are methods missing from SugaredLogger that do exist on zap.
(the ones without formatting)
were there a reason why you didnt add them?
Im guessing it should look like:
Should I go ahead and implement those for all levels?
Cheers 🥂
The text was updated successfully, but these errors were encountered: