Skip to content

Commit

Permalink
Write to /dev/stderr in a cross-platform way by default (#41)
Browse files Browse the repository at this point in the history
fixes #23
  • Loading branch information
nlowe authored and boz committed Aug 9, 2019
1 parent 16ce9ed commit 9d98f1d
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions cmd/kail/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ var (
Bool()

flagLogFile = kingpin.Flag("log-file", "log file output").
Default("/dev/stderr").
String()

flagLogLevel = kingpin.Flag("log-level", "log level").
Expand Down Expand Up @@ -148,12 +147,16 @@ func createLog() logutil.Log {
lvl, err := logrus.ParseLevel(*flagLogLevel)
kingpin.FatalIfError(err, "Invalid log level")

file, err := os.OpenFile(*flagLogFile, os.O_WRONLY|os.O_APPEND|os.O_CREATE, 0644)
kingpin.FatalIfError(err, "Error opening log file")

parent := logrus.New()
parent.Level = lvl
parent.Out = file

if *flagLogFile != "" {
file, err := os.OpenFile(*flagLogFile, os.O_WRONLY|os.O_APPEND|os.O_CREATE, 0644)
kingpin.FatalIfError(err, "Error opening log file")
parent.Out = file
} else {
parent.Out = os.Stderr
}

return logutil_logrus.New(parent).WithComponent("kail.main")
}
Expand Down

0 comments on commit 9d98f1d

Please sign in to comment.