add quote method to config log messages

This commit is contained in:
Bradley Cicenas
2017-02-18 14:30:54 +11:00
parent 8d9e6fd273
commit 3c28137873
2 changed files with 8 additions and 3 deletions

View File

@@ -1,6 +1,7 @@
package config package config
import ( import (
"fmt"
"os" "os"
"github.com/bcicen/ctop/logging" "github.com/bcicen/ctop/logging"
@@ -15,15 +16,19 @@ var (
func Init() { func Init() {
for _, p := range params { for _, p := range params {
GlobalParams = append(GlobalParams, p) GlobalParams = append(GlobalParams, p)
log.Infof("loaded config param: \"%s\": \"%s\"", p.Key, p.Val) log.Infof("loaded config param: %s: %s", quote(p.Key), quote(p.Val))
} }
for _, s := range switches { for _, s := range switches {
GlobalSwitches = append(GlobalSwitches, s) GlobalSwitches = append(GlobalSwitches, s)
log.Infof("loaded config switch: \"%s\": %t", s.Key, s.Val) log.Infof("loaded config switch: %s: %t", quote(s.Key), s.Val)
} }
} }
func quote(s string) string {
return fmt.Sprintf("\"%s\"", s)
}
// Return env var value if set, else return defaultVal // Return env var value if set, else return defaultVal
func getEnv(key, defaultVal string) string { func getEnv(key, defaultVal string) string {
val := os.Getenv(key) val := os.Getenv(key)

View File

@@ -43,7 +43,7 @@ func GetVal(k string) string {
// Set param value // Set param value
func Update(k, v string) { func Update(k, v string) {
p := Get(k) p := Get(k)
log.Noticef("config change: %s: %s -> %s", k, p.Val, v) log.Noticef("config change: %s: %s -> %s", k, quote(p.Val), quote(v))
p.Val = v p.Val = v
// log.Errorf("ignoring update for non-existant parameter: %s", k) // log.Errorf("ignoring update for non-existant parameter: %s", k)
} }