-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
remove debug and fatal levels. change attribute type to slog.Attr.
- Loading branch information
Showing
11 changed files
with
79 additions
and
188 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package corelog | ||
|
||
import "log/slog" | ||
|
||
// namedLeveler is an slog.Leveler that gets its value from a named config. | ||
type namedLeveler string | ||
|
||
func (n namedLeveler) Level() slog.Level { | ||
switch cfg := GetConfig(string(n)); cfg.Level { | ||
case LevelInfo: | ||
return slog.LevelInfo | ||
case LevelError: | ||
return slog.LevelError | ||
default: | ||
// default to info if no value is set | ||
// or the set value is invalid | ||
return slog.LevelInfo | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package corelog | ||
|
||
import ( | ||
"log/slog" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestNamedLeveler(t *testing.T) { | ||
leveler := namedLeveler("core") | ||
assert.Equal(t, slog.LevelInfo, leveler.Level()) | ||
|
||
SetConfigOverride("core", Config{Level: LevelInfo}) | ||
assert.Equal(t, slog.LevelInfo, leveler.Level()) | ||
|
||
SetConfigOverride("core", Config{Level: LevelError}) | ||
assert.Equal(t, slog.LevelError, leveler.Level()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.