Skip to content

Commit

Permalink
feat: Allow configuring log level via env
Browse files Browse the repository at this point in the history
  • Loading branch information
tonyo committed Jun 28, 2019
1 parent d1d623c commit e6343da
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package main
import (
"os"
"os/signal"
"strings"
"syscall"
"time"

Expand Down Expand Up @@ -73,17 +74,29 @@ func catchInterrupt() {
}

func initLogging() {

log.SetFormatter(&logrus.TextFormatter{
FullTimestamp: true,
})

var logLevel = logrus.InfoLevel

logLevelEnv := strings.ToLower(os.Getenv("SENTLOG_LOG_LEVEL"))
switch logLevelEnv {
case "debug":
logLevel = logrus.DebugLevel
case "info":
logLevel = logrus.InfoLevel
}
log.SetLevel(logLevel)
}

func showGreeting() {

}

func main() {
initLogging()

args := CmdArgs{
file: kingpin.Arg("file", "File to parse").String(),
pattern: kingpin.Flag("pattern", "Pattern to look for").Short('p').String(),
Expand All @@ -93,11 +106,8 @@ func main() {
config: kingpin.Flag("config", "Path to the configuration").Short('c').String(),
verbose: kingpin.Flag("verbose", "Print every match").Short('v').Default("false").Bool(),
}

kingpin.Parse()

initLogging()

showGreeting()

_isDryRun = *args.dryRun
Expand Down

0 comments on commit e6343da

Please sign in to comment.