From b7cc31863de00e577764e7b257c16e7645cd86af Mon Sep 17 00:00:00 2001 From: David Pordomingo Date: Thu, 24 Oct 2019 17:37:38 +0200 Subject: [PATCH] Use LOG_LEVEL env value to set logrus log level LOG_LEVEL can be any of debug, info, warning, error If bblfsh backend is ran with --debug flag, log level will be 'trace' Signed-off-by: David Pordomingo --- README.md | 9 +++++++++ server/cmd/bblfsh-web/main.go | 12 ++++++++++++ 2 files changed, 21 insertions(+) diff --git a/README.md b/README.md index 2265aa80..faafd06b 100644 --- a/README.md +++ b/README.md @@ -30,6 +30,15 @@ If you don't want to run the **web client** using our *Docker* image you can dow ./bblfsh-web -bblfsh-addr ``` +You can also configure the server in debug mode passing `--debug` extra flag, and the logging level with the `LOG_LEVEL` environment value: + +```sh +LOG_LEVEL={debug,info,warning error} ./bblfsh-web -bblfsh-addr --debug +``` + +If none are set, its default values will be logging level `info`, and server in `ReleaseMode`. + + ## Development See [CONTRIBUTING.md](CONTRIBUTING.md). There is information about the [application architecture](CONTRIBUTING.md#Architecture) and how to [build](CONTRIBUTING.md#Development) from sources. diff --git a/server/cmd/bblfsh-web/main.go b/server/cmd/bblfsh-web/main.go index f2d4ffd7..c140bdc7 100644 --- a/server/cmd/bblfsh-web/main.go +++ b/server/cmd/bblfsh-web/main.go @@ -5,6 +5,7 @@ import ( "fmt" "log" "net/http" + "os" "time" "github.com/bblfsh/web/server" @@ -25,6 +26,13 @@ func flags() (addr, bblfshAddr string, debug, version bool) { return } +var logLevels = map[string]logrus.Level{ + "debug": logrus.DebugLevel, + "info": logrus.InfoLevel, + "warning": logrus.WarnLevel, + "error": logrus.ErrorLevel, +} + func main() { addr, bblfshAddr, debug, showVersion := flags() @@ -33,6 +41,10 @@ func main() { return } + if level, ok := logLevels[os.Getenv("LOG_LEVEL")]; ok { + logrus.SetLevel(level) + } + if !debug { gin.SetMode(gin.ReleaseMode) }