small fixups
Some checks failed
pr / test (pull_request) Failing after 1m6s
lint / lint (pull_request) Successful in 10m45s

Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
This commit is contained in:
2024-10-12 12:36:08 +03:00
parent ced277ff57
commit 8a9243636e
7 changed files with 31 additions and 48 deletions

View File

@@ -14,8 +14,6 @@ var (
DefaultLogger Logger = NewLogger()
// DefaultLevel used by logger
DefaultLevel = InfoLevel
// defaultCallerSkipCount used by logger
defaultCallerSkipCount = 3
)
// Logger is a generic logging interface

View File

@@ -4,12 +4,17 @@ import (
"context"
)
const (
defaultCallerSkipCount = 2
)
type noopLogger struct {
opts Options
}
func NewLogger(opts ...Option) Logger {
options := NewOptions(opts...)
options.CallerSkipCount = defaultCallerSkipCount
return &noopLogger{opts: options}
}
@@ -71,24 +76,3 @@ func (l *noopLogger) Warn(ctx context.Context, msg string, attrs ...interface{})
func (l *noopLogger) Fatal(ctx context.Context, msg string, attrs ...interface{}) {
}
func (l *noopLogger) Logf(ctx context.Context, lvl Level, msg string, attrs ...interface{}) {
}
func (l *noopLogger) Infof(ctx context.Context, msg string, attrs ...interface{}) {
}
func (l *noopLogger) Debugf(ctx context.Context, msg string, attrs ...interface{}) {
}
func (l *noopLogger) Errorf(ctx context.Context, msg string, attrs ...interface{}) {
}
func (l *noopLogger) Tracef(ctx context.Context, msg string, attrs ...interface{}) {
}
func (l *noopLogger) Warnf(ctx context.Context, msg string, attrs ...interface{}) {
}
func (l *noopLogger) Fatalf(ctx context.Context, msg string, attrs ...interface{}) {
}

View File

@@ -54,7 +54,6 @@ type Options struct {
// NewOptions creates new options struct
func NewOptions(opts ...Option) Options {
options := Options{
CallerSkipCount: defaultCallerSkipCount,
Level: DefaultLevel,
Fields: make([]interface{}, 0, 6),
Out: os.Stderr,

View File

@@ -16,8 +16,9 @@ import (
const (
badKey = "!BADKEY"
// defaultCallerSkipCount used by logger
defaultCallerSkipCount = 3
)
const emptyMSg = "!EMPTYMSG"
var reTrace = regexp.MustCompile(`.*/slog/logger\.go.*\n`)
@@ -192,11 +193,12 @@ func (s *slogLogger) String() string {
}
func (s *slogLogger) printLog(ctx context.Context, lvl logger.Level, msg string, attrs ...interface{}) {
s.opts.Meter.Counter(semconv.LoggerMessageTotal, "level", lvl.String()).Inc()
if !s.V(lvl) {
return
}
s.opts.Meter.Counter(semconv.LoggerMessageTotal, "level", lvl.String()).Inc()
attrs = prepareAttributes(attrs)
for _, fn := range s.opts.ContextAttrFuncs {
@@ -235,6 +237,7 @@ func NewLogger(opts ...logger.Option) logger.Logger {
s := &slogLogger{
opts: logger.NewOptions(opts...),
}
s.opts.CallerSkipCount = defaultCallerSkipCount
return s
}