From 7506bd000e605d2f8c4f7069e1fbf9e6022e3e71 Mon Sep 17 00:00:00 2001 From: Christian Pointner Date: Sun, 3 Jan 2016 20:15:47 +0100 Subject: make debug log runtime configurable diff --git a/src/helsinki.at/rhimport/core.go b/src/helsinki.at/rhimport/core.go index 1824db1..58633d8 100644 --- a/src/helsinki.at/rhimport/core.go +++ b/src/helsinki.at/rhimport/core.go @@ -25,9 +25,9 @@ package rhimport import ( - // "io/ioutil" "fmt" "github.com/golang-basic/go-curl" + "io/ioutil" "log" "os" ) @@ -40,11 +40,13 @@ const ( var ( bool2str = map[bool]string{false: "0", true: "1"} rhl = log.New(os.Stderr, "[rhimport]\t", log.LstdFlags) - rhdl = log.New(os.Stderr, "[rhimport-dbg]\t", log.LstdFlags) - //rhdl = log.New(ioutil.Discard, "[rhimport-dbg]\t", log.LstdFlags) + rhdl = log.New(ioutil.Discard, "[rhimport-dbg]\t", log.LstdFlags) ) func init() { + if _, exists := os.LookupEnv("RHIMPORT_DEBUG"); exists { + rhdl.SetOutput(os.Stderr) + } curl.GlobalInit(curl.GLOBAL_ALL) fetcherInit() } diff --git a/src/helsinki.at/rhimportd/main.go b/src/helsinki.at/rhimportd/main.go index c6090cb..b449d5c 100644 --- a/src/helsinki.at/rhimportd/main.go +++ b/src/helsinki.at/rhimportd/main.go @@ -28,19 +28,24 @@ import ( "flag" "fmt" "helsinki.at/rhimport" + "io/ioutil" "log" "os" "os/signal" "sync" - // "io/ioutil" ) var ( rhl = log.New(os.Stderr, "[rhimportd]\t", log.LstdFlags) - rhdl = log.New(os.Stderr, "[rhimportd-dbg]\t", log.LstdFlags) - //rhdl = log.New(ioutil.Discard, "[rhimportd-dbg]\t", log.LstdFlags) + rhdl = log.New(ioutil.Discard, "[rhimportd-dbg]\t", log.LstdFlags) ) +func init() { + if _, exists := os.LookupEnv("RHIMPORTD_DEBUG"); exists { + rhdl.SetOutput(os.Stderr) + } +} + type envStringValue string func newEnvStringValue(key, dflt string) *envStringValue { -- cgit v0.10.2