constellation/internal/logger/cmdline.go

31 lines
669 B
Go
Raw Normal View History

/*
Copyright (c) Edgeless Systems GmbH
SPDX-License-Identifier: AGPL-3.0-only
*/
package logger
import (
2024-02-08 09:20:01 -05:00
"log/slog"
)
// 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"
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 {
switch {
case verbosity <= -1:
2024-02-08 09:20:01 -05:00
return slog.LevelDebug
case verbosity == 0:
2024-02-08 09:20:01 -05:00
return slog.LevelInfo
case verbosity == 1:
2024-02-08 09:20:01 -05:00
return slog.LevelWarn
case verbosity >= 2:
2024-02-08 09:20:01 -05:00
return slog.LevelError
default:
2024-02-08 09:20:01 -05:00
return slog.LevelInfo
}
}