2022-09-05 03:06:08 -04:00
|
|
|
/*
|
|
|
|
Copyright (c) Edgeless Systems GmbH
|
|
|
|
|
|
|
|
SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
*/
|
|
|
|
|
2022-07-01 10:17:06 -04:00
|
|
|
package logger
|
|
|
|
|
|
|
|
import (
|
2024-02-08 09:20:01 -05:00
|
|
|
"log/slog"
|
2022-07-01 10:17:06 -04:00
|
|
|
)
|
|
|
|
|
2022-11-09 09:57:54 -05:00
|
|
|
// CmdLineVerbosityDescription explains numeric log levels.
|
2024-02-08 09:20:01 -05:00
|
|
|
const CmdLineVerbosityDescription = "log verbosity: Use -1 for debug information, 0 for info, 1 for warn, 2 for error"
|
2022-07-01 10:17:06 -04:00
|
|
|
|
2024-02-08 09:20:01 -05:00
|
|
|
// VerbosityFromInt converts a verbosity level from an integer to a slog.Level.
|
|
|
|
func VerbosityFromInt(verbosity int) slog.Level {
|
2022-07-01 10:17:06 -04:00
|
|
|
switch {
|
|
|
|
case verbosity <= -1:
|
2024-02-08 09:20:01 -05:00
|
|
|
return slog.LevelDebug
|
2022-07-01 10:17:06 -04:00
|
|
|
case verbosity == 0:
|
2024-02-08 09:20:01 -05:00
|
|
|
return slog.LevelInfo
|
2022-07-01 10:17:06 -04:00
|
|
|
case verbosity == 1:
|
2024-02-08 09:20:01 -05:00
|
|
|
return slog.LevelWarn
|
2022-07-01 10:17:06 -04:00
|
|
|
case verbosity >= 2:
|
2024-02-08 09:20:01 -05:00
|
|
|
return slog.LevelError
|
2022-07-01 10:17:06 -04:00
|
|
|
default:
|
2024-02-08 09:20:01 -05:00
|
|
|
return slog.LevelInfo
|
2022-07-01 10:17:06 -04:00
|
|
|
}
|
|
|
|
}
|