@@ -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
|
||||
|
||||
@@ -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{}) {
|
||||
}
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user