Skip to content

Commit

Permalink
Merge pull request #1 from KevinPike/master
Browse files Browse the repository at this point in the history
set log level using environment
  • Loading branch information
kbudde committed Nov 10, 2015
2 parents 5c970d7 + 0363079 commit be31357
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,17 @@ package main

import (
"net/http"
"os"
"strings"

log "github.com/Sirupsen/logrus"
"github.com/prometheus/client_golang/prometheus"
)

const defaultLogLevel = log.InfoLevel

func initLogger() {
log.SetLevel(getLogLevel())
if strings.ToUpper(config.OutputFormat) == "JSON" {
log.SetFormatter(&log.JSONFormatter{})
} else {
Expand Down Expand Up @@ -44,3 +48,12 @@ func main() {

log.Fatal(http.ListenAndServe(":"+config.PublishPort, nil))
}

func getLogLevel() log.Level {
lvl := strings.ToLower(os.Getenv("LOG_LEVEL"))
level, err := log.ParseLevel(lvl)
if err != nil {
level = defaultLogLevel
}
return level
}

0 comments on commit be31357

Please sign in to comment.