mirror of
https://github.com/bcicen/ctop.git
synced 2025-12-06 15:16:41 +08:00
add quote method to config log messages
This commit is contained in:
@@ -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)
|
||||||
|
|||||||
@@ -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)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user