-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Squashed commit of the following: commit 444cf5e Author: Dimitry Kolyshev <[email protected]> Date: Tue Oct 1 15:49:52 2024 +0300 slogutil: imp code commit e1e6a7c Author: Dimitry Kolyshev <[email protected]> Date: Tue Oct 1 15:45:49 2024 +0300 slogutil: imp code commit e9e5ef0 Author: Dimitry Kolyshev <[email protected]> Date: Tue Oct 1 15:21:42 2024 +0300 slogutil: imp code commit f3def15 Author: Dimitry Kolyshev <[email protected]> Date: Tue Oct 1 15:15:20 2024 +0300 slogutil: default commit a79518e Author: Dimitry Kolyshev <[email protected]> Date: Tue Oct 1 15:09:52 2024 +0300 all: legacy trace log commit 86e7acf Author: Dimitry Kolyshev <[email protected]> Date: Mon Sep 30 10:58:08 2024 +0300 all: legacy trace log commit 954d7d2 Author: Dimitry Kolyshev <[email protected]> Date: Mon Sep 30 10:09:29 2024 +0300 slogutil: imp code commit e9b9a24 Author: Dimitry Kolyshev <[email protected]> Date: Fri Sep 27 11:32:24 2024 +0700 slogutil: replace level name commit 1aa7a3a Author: Dimitry Kolyshev <[email protected]> Date: Fri Sep 27 09:54:03 2024 +0700 slogutil: imp code commit 8e07d8a Author: Dimitry Kolyshev <[email protected]> Date: Fri Sep 27 08:16:27 2024 +0700 slogutil: imp code commit c9ee827 Author: Dimitry Kolyshev <[email protected]> Date: Thu Sep 26 15:09:44 2024 +0700 slogutil: trace
- Loading branch information
Showing
5 changed files
with
94 additions
and
18 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package slogutil | ||
|
||
import ( | ||
"fmt" | ||
"log/slog" | ||
|
||
"github.com/AdguardTeam/golibs/errors" | ||
) | ||
|
||
// Acceptable [slog.Level] levels. | ||
const ( | ||
LevelTrace = slog.Level(-8) | ||
LevelDebug = slog.LevelDebug | ||
LevelInfo = slog.LevelInfo | ||
LevelWarn = slog.LevelWarn | ||
LevelError = slog.LevelError | ||
) | ||
|
||
// VerbosityToLevel returns log level for given verbosity. | ||
func VerbosityToLevel(l uint8) (lvl slog.Level, err error) { | ||
switch l { | ||
case 0: | ||
return LevelInfo, nil | ||
case 1: | ||
return LevelDebug, nil | ||
case 2: | ||
return LevelTrace, nil | ||
default: | ||
return lvl, fmt.Errorf("%w: %d", errors.ErrBadEnumValue, l) | ||
} | ||
} |