Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
aymanbagabas committed Feb 5, 2024
1 parent f2cb6b6 commit bebe584
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 3 deletions.
14 changes: 13 additions & 1 deletion level_121.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@

package log

import "log/slog"
import (
"log/slog"
)

// fromSlogLevel converts slog.Level to log.Level.
var fromSlogLevel = map[slog.Level]Level{
Expand All @@ -13,3 +15,13 @@ var fromSlogLevel = map[slog.Level]Level{
slog.LevelError: ErrorLevel,
slog.Level(12): FatalLevel,
}

var _ slog.Leveler = Level(0)

// Leveler is a dynamic logging leveler.
type Leveler = slog.Leveler

// Level implements slog.Leveler.
func (l Level) Level() slog.Level {
return slog.Level(l)
}
10 changes: 10 additions & 0 deletions level_no121.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,13 @@ var fromSlogLevel = map[slog.Level]Level{
slog.LevelError: ErrorLevel,
slog.Level(12): FatalLevel,
}

var _ slog.Leveler = Level(0)

// Leveler is a dynamic logging leveler.
type Leveler = slog.Leveler

// Level implements slog.Leveler.
func (l Level) Level() slog.Level {
return slog.Level(l)
}
5 changes: 3 additions & 2 deletions logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ type Logger struct {
isDiscard uint32

level int32
leveler Leveler
prefix string
timeFunc TimeFunction
timeFormat string
Expand Down Expand Up @@ -233,10 +234,10 @@ func (l *Logger) GetLevel() Level {
}

// SetLevel sets the current level.
func (l *Logger) SetLevel(level Level) {
func (l *Logger) SetLevel(level Leveler) {
l.mu.Lock()
defer l.mu.Unlock()
atomic.StoreInt32(&l.level, int32(level))
l.leveler = level
}

// GetPrefix returns the current prefix.
Expand Down

0 comments on commit bebe584

Please sign in to comment.