diff options
author | Jesse Duffield <jessedduffield@gmail.com> | 2019-03-16 10:37:31 +1100 |
---|---|---|
committer | Jesse Duffield <jessedduffield@gmail.com> | 2019-03-16 10:52:30 +1100 |
commit | 39844ffef9987a8ee6ff97d68491dc766079f07b (patch) | |
tree | 5bc55804a9318e688cbf126cb1d587290ea32ee8 | |
parent | f5c8aac97d51e2173b7abf4441e6e997734c3593 (diff) |
allow a LOG_LEVEL env var to be set
-rw-r--r-- | pkg/app/app.go | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/pkg/app/app.go b/pkg/app/app.go index 4c895f521..c5bfd516f 100644 --- a/pkg/app/app.go +++ b/pkg/app/app.go @@ -35,6 +35,7 @@ type App struct { func newProductionLogger(config config.AppConfigurer) *logrus.Logger { log := logrus.New() log.Out = ioutil.Discard + log.SetLevel(logrus.ErrorLevel) return log } @@ -44,8 +45,18 @@ func globalConfigDir() string { return configDir.Path } +func getLogLevel() logrus.Level { + strLevel := os.Getenv("LOG_LEVEL") + level, err := logrus.ParseLevel(strLevel) + if err != nil { + return logrus.DebugLevel + } + return level +} + func newDevelopmentLogger(config config.AppConfigurer) *logrus.Logger { log := logrus.New() + log.SetLevel(getLogLevel()) file, err := os.OpenFile(filepath.Join(globalConfigDir(), "development.log"), os.O_CREATE|os.O_WRONLY|os.O_APPEND, 0666) if err != nil { panic("unable to log to file") // TODO: don't panic (also, remove this call to the `panic` function) |