From f954dc8f8b7968e92d184db10a943e5d62e99105 Mon Sep 17 00:00:00 2001 From: Jason Hall Date: Wed, 11 Sep 2024 11:18:34 -0500 Subject: [PATCH] change type of Level to int (#141) * change type of Level to int Signed-off-by: Jason Hall * support <1.21 Signed-off-by: Jason Hall --------- Signed-off-by: Jason Hall --- level.go | 4 ++-- logger.go | 6 +++--- logger_121.go | 2 +- logger_no121.go | 2 +- pkg.go | 2 +- 5 files changed, 8 insertions(+), 8 deletions(-) diff --git a/level.go b/level.go index cba2297..1c2ce8e 100644 --- a/level.go +++ b/level.go @@ -8,7 +8,7 @@ import ( ) // Level is a logging level. -type Level int32 +type Level int const ( // DebugLevel is the debug level. @@ -22,7 +22,7 @@ const ( // FatalLevel is the fatal level. FatalLevel Level = 12 // noLevel is used with log.Print. - noLevel Level = math.MaxInt32 + noLevel Level = math.MaxInt ) // String returns the string representation of the level. diff --git a/logger.go b/logger.go index f4120c1..ece9349 100644 --- a/logger.go +++ b/logger.go @@ -30,7 +30,7 @@ type Logger struct { isDiscard uint32 - level int32 + level int64 prefix string timeFunc TimeFunction timeFormat string @@ -59,7 +59,7 @@ func (l *Logger) Log(level Level, msg interface{}, keyvals ...interface{}) { } // check if the level is allowed - if atomic.LoadInt32(&l.level) > int32(level) { + if atomic.LoadInt64(&l.level) > int64(level) { return } @@ -234,7 +234,7 @@ func (l *Logger) GetLevel() Level { func (l *Logger) SetLevel(level Level) { l.mu.Lock() defer l.mu.Unlock() - atomic.StoreInt32(&l.level, int32(level)) + atomic.StoreInt64(&l.level, int64(level)) } // GetPrefix returns the current prefix. diff --git a/logger_121.go b/logger_121.go index 73bee9c..b5cf956 100644 --- a/logger_121.go +++ b/logger_121.go @@ -23,7 +23,7 @@ const slogKindGroup = slog.KindGroup // // Implements slog.Handler. func (l *Logger) Enabled(_ context.Context, level slog.Level) bool { - return atomic.LoadInt32(&l.level) <= int32(level) + return atomic.LoadInt64(&l.level) <= int64(level) } // Handle handles the Record. It will only be called if Enabled returns true. diff --git a/logger_no121.go b/logger_no121.go index bf28cf4..ce8b8a2 100644 --- a/logger_no121.go +++ b/logger_no121.go @@ -24,7 +24,7 @@ const slogKindGroup = slog.KindGroup // // Implements slog.Handler. func (l *Logger) Enabled(_ context.Context, level slog.Level) bool { - return atomic.LoadInt32(&l.level) <= int32(level) + return atomic.LoadInt64(&l.level) <= int64(level) } // Handle handles the Record. It will only be called if Enabled returns true. diff --git a/pkg.go b/pkg.go index 9e083a3..712bb38 100644 --- a/pkg.go +++ b/pkg.go @@ -52,7 +52,7 @@ func NewWithOptions(w io.Writer, o Options) *Logger { b: bytes.Buffer{}, mu: &sync.RWMutex{}, helpers: &sync.Map{}, - level: int32(o.Level), + level: int64(o.Level), reportTimestamp: o.ReportTimestamp, reportCaller: o.ReportCaller, prefix: o.Prefix,