Skip to content

Commit

Permalink
Use LOG_LEVEL env value to set logrus log level
Browse files Browse the repository at this point in the history
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 <David.Pordomingo.F@gmail.com>
  • Loading branch information
dpordomingo committed Oct 28, 2019
1 parent 73f2105 commit b7cc318
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 <bblfsh-server-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 <bblfsh-server-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.
Expand Down
12 changes: 12 additions & 0 deletions server/cmd/bblfsh-web/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"fmt"
"log"
"net/http"
"os"
"time"

"github.com/bblfsh/web/server"
Expand All @@ -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()

Expand All @@ -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)
}
Expand Down

0 comments on commit b7cc318

Please # to comment.