From 05937cdba0f5d1ab01aba48f0a9d64db9c98c9a9 Mon Sep 17 00:00:00 2001 From: Daniil Antoshin Date: Thu, 14 Nov 2024 11:30:02 +0200 Subject: [PATCH] refactor(logger): hide detect functions and add fatal log level Signed-off-by: Daniil Antoshin --- .../virtualization-artifact/pkg/logger/logger.go | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/images/virtualization-artifact/pkg/logger/logger.go b/images/virtualization-artifact/pkg/logger/logger.go index 4e87c0b85..ec38f131d 100644 --- a/images/virtualization-artifact/pkg/logger/logger.go +++ b/images/virtualization-artifact/pkg/logger/logger.go @@ -43,33 +43,36 @@ var DefaultLogOutput = os.Stdout func NewLogger(level, output string, debugVerbosity int) *log.Logger { return log.NewLogger(log.Options{ - Level: DetectLogLevel(level, debugVerbosity), - Output: DetectLogOutput(output), + Level: detectLogLevel(level, debugVerbosity), + Output: detectLogOutput(output), }) } -func DetectLogLevel(level string, debugVerbosity int) slog.Level { + +func detectLogLevel(level string, debugVerbosity int) slog.Level { switch strings.ToLower(level) { + case "fatal": + return log.LevelFatal.Level() case "error": return log.LevelError.Level() case "warn": return log.LevelWarn.Level() case "info": return log.LevelInfo.Level() - case "trace": - return log.LevelTrace.Level() case "debug": if debugVerbosity != 0 { return slog.Level(-1 * debugVerbosity) } return log.LevelDebug.Level() + case "trace": + return log.LevelTrace.Level() default: return DefaultLogLevel.Level() } } -func DetectLogOutput(output string) io.Writer { +func detectLogOutput(output string) io.Writer { switch strings.ToLower(output) { case string(Stdout): return os.Stdout