Skip to content

Commit

Permalink
Merge pull request #227 from dpordomingo/logs
Browse files Browse the repository at this point in the history
Signed-off-by: David Pordomingo <[email protected]>
  • Loading branch information
dpordomingo authored Oct 28, 2019
2 parents 73f2105 + b914a9a commit 01521fa
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
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
14 changes: 13 additions & 1 deletion 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 @@ -18,13 +19,20 @@ var version = "dev"
func flags() (addr, bblfshAddr string, debug, version bool) {
flag.StringVar(&addr, "addr", ":9999", "address in which the server will run")
flag.StringVar(&bblfshAddr, "bblfsh-addr", "0.0.0.0:9432", "address of the babelfish server")
flag.BoolVar(&debug, "debug", false, "run in debug mode")
flag.BoolVar(&debug, "debug", false, "run the server in debug mode")
flag.BoolVar(&version, "version", false, "show version and exits")
flag.Parse()

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 01521fa

Please sign in to comment.