Skip to content

Commit

Permalink
change type of Level to int (#141)
Browse files Browse the repository at this point in the history
* change type of Level to int

Signed-off-by: Jason Hall <[email protected]>

* support <1.21

Signed-off-by: Jason Hall <[email protected]>

---------

Signed-off-by: Jason Hall <[email protected]>
  • Loading branch information
imjasonh authored Sep 11, 2024
1 parent 958009c commit f954dc8
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 8 deletions.
4 changes: 2 additions & 2 deletions level.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
)

// Level is a logging level.
type Level int32
type Level int

const (
// DebugLevel is the debug level.
Expand All @@ -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.
Expand Down
6 changes: 3 additions & 3 deletions logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ type Logger struct {

isDiscard uint32

level int32
level int64
prefix string
timeFunc TimeFunction
timeFormat string
Expand Down Expand Up @@ -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
}

Expand Down Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion logger_121.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion logger_no121.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion pkg.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit f954dc8

Please sign in to comment.