Skip to content

Commit

Permalink
Allow setting any log level
Browse files Browse the repository at this point in the history
It would be useful to set a specific log level by providing a string as other levels apart from info and debug are useful.

Have prioritised the existing debug flag for backwards compatibility but would recommend its removal.
  • Loading branch information
stanleyrh authored and Admiral-Piett committed Jan 9, 2024
1 parent bd7b575 commit 5cd3a92
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions app/cmd/goaws.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ func main() {
var filename string
var debug bool
flag.StringVar(&filename, "config", "", "config file location + name")
flag.BoolVar(&debug, "debug", false, "debug log level (default Warning)")
flag.BoolVar(&debug, "debug", false, "set debug log level")
flag.StringVar(&loglevel, "loglevel", "info", "log level (default info)")
flag.Parse()

log.SetFormatter(&log.JSONFormatter{})
Expand All @@ -28,7 +29,13 @@ func main() {
if debug {
log.SetLevel(log.DebugLevel)
} else {
log.SetLevel(log.InfoLevel)
level, err := log.ParseLevel(loglevel)
if err != nil {
log.SetLevel(log.InfoLevel)
log.Warnf("Failed to parse loglevel %v, defaulting to info", loglevel)
} else {
log.SetLevel(level)
}
}

env := "Local"
Expand Down

0 comments on commit 5cd3a92

Please sign in to comment.