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 24, 2019
1 parent 73f2105 commit b232e88
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 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,8 +41,14 @@ func main() {
return
}

if level, ok := logLevels[os.Getenv("LOG_LEVEL")]; ok {
logrus.SetLevel(level)
}

if !debug {
gin.SetMode(gin.ReleaseMode)
} else {
logrus.SetLevel(logrus.TraceLevel)
}

s, err := server.New(bblfshAddr, version)
Expand Down

0 comments on commit b232e88

Please # to comment.