Skip to content

Commit

Permalink
refactor(logger): hide detect functions and add fatal log level
Browse files Browse the repository at this point in the history
Signed-off-by: Daniil Antoshin <[email protected]>
  • Loading branch information
danilrwx committed Nov 14, 2024
1 parent 92c89f3 commit 05937cd
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions images/virtualization-artifact/pkg/logger/logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 05937cd

Please sign in to comment.