Skip to content

Commit 01521fa

Browse files
authored
Merge pull request #227 from dpordomingo/logs
Signed-off-by: David Pordomingo <[email protected]>
2 parents 73f2105 + b914a9a commit 01521fa

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

README.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,15 @@ If you don't want to run the **web client** using our *Docker* image you can dow
3030
./bblfsh-web -bblfsh-addr <bblfsh-server-addr>
3131
```
3232

33+
You can also configure the server in debug mode passing `--debug` extra flag, and the logging level with the `LOG_LEVEL` environment value:
34+
35+
```sh
36+
LOG_LEVEL={debug,info,warning error} ./bblfsh-web -bblfsh-addr <bblfsh-server-addr> --debug
37+
```
38+
39+
If none are set, its default values will be logging level `info`, and server in `ReleaseMode`.
40+
41+
3342
## Development
3443

3544
See [CONTRIBUTING.md](CONTRIBUTING.md). There is information about the [application architecture](CONTRIBUTING.md#Architecture) and how to [build](CONTRIBUTING.md#Development) from sources.

server/cmd/bblfsh-web/main.go

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"fmt"
66
"log"
77
"net/http"
8+
"os"
89
"time"
910

1011
"github.com/bblfsh/web/server"
@@ -18,13 +19,20 @@ var version = "dev"
1819
func flags() (addr, bblfshAddr string, debug, version bool) {
1920
flag.StringVar(&addr, "addr", ":9999", "address in which the server will run")
2021
flag.StringVar(&bblfshAddr, "bblfsh-addr", "0.0.0.0:9432", "address of the babelfish server")
21-
flag.BoolVar(&debug, "debug", false, "run in debug mode")
22+
flag.BoolVar(&debug, "debug", false, "run the server in debug mode")
2223
flag.BoolVar(&version, "version", false, "show version and exits")
2324
flag.Parse()
2425

2526
return
2627
}
2728

29+
var logLevels = map[string]logrus.Level{
30+
"debug": logrus.DebugLevel,
31+
"info": logrus.InfoLevel,
32+
"warning": logrus.WarnLevel,
33+
"error": logrus.ErrorLevel,
34+
}
35+
2836
func main() {
2937
addr, bblfshAddr, debug, showVersion := flags()
3038

@@ -33,6 +41,10 @@ func main() {
3341
return
3442
}
3543

44+
if level, ok := logLevels[os.Getenv("LOG_LEVEL")]; ok {
45+
logrus.SetLevel(level)
46+
}
47+
3648
if !debug {
3749
gin.SetMode(gin.ReleaseMode)
3850
}

0 commit comments

Comments
 (0)