Skip to content

Commit

Permalink
refactor: refine setting logging level func
Browse files Browse the repository at this point in the history
  • Loading branch information
voldikss committed May 27, 2023
1 parent 14d52e8 commit 1b1766e
Showing 1 changed file with 22 additions and 18 deletions.
40 changes: 22 additions & 18 deletions config.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,23 +48,27 @@ func init() {
}

if loggingLevel := os.Getenv("LOGGING_LEVEL"); len(loggingLevel) > 0 {
switch loggingLevel {
case "panic", "Panic", "PANIC":
log.SetLevel(log.PanicLevel)
case "fatal", "Fatal", "FATAL":
log.SetLevel(log.FatalLevel)
case "error", "Error", "ERROR":
log.SetLevel(log.ErrorLevel)
case "warn", "Warn", "WARN":
log.SetLevel(log.WarnLevel)
case "info", "Info", "INFO":
log.SetLevel(log.InfoLevel)
case "debug", "Debug", "DEBUG":
log.SetLevel(log.DebugLevel)
case "trace", "Trace", "TRACE":
log.SetLevel(log.TraceLevel)
default:
log.Panicln("unknown logging level:", loggingLevel)
}
setupLoggingLevel(loggingLevel)
}
}

func setupLoggingLevel(l string) {
switch l {
case "panic", "Panic", "PANIC":
log.SetLevel(log.PanicLevel)
case "fatal", "Fatal", "FATAL":
log.SetLevel(log.FatalLevel)
case "error", "Error", "ERROR":
log.SetLevel(log.ErrorLevel)
case "warn", "Warn", "WARN":
log.SetLevel(log.WarnLevel)
case "info", "Info", "INFO":
log.SetLevel(log.InfoLevel)
case "debug", "Debug", "DEBUG":
log.SetLevel(log.DebugLevel)
case "trace", "Trace", "TRACE":
log.SetLevel(log.TraceLevel)
default:
log.Panicln("unknown logging level:", l)
}
}

0 comments on commit 1b1766e

Please sign in to comment.