summaryrefslogtreecommitdiffstats
path: root/bridge
diff options
context:
space:
mode:
authorWim <wim@42.be>2018-05-01 22:23:37 +0200
committerWim <wim@42.be>2018-05-01 22:23:37 +0200
commit96a47a60adc3301106c3f27c39c0ba03e2ebe177 (patch)
tree0be3429cc516372c20dfa6639a6af277e59fae05 /bridge
parentb24a47ad7fb6950d19cb160ede1d3804f66e9928 (diff)
downloadmatterbridge-msglm-96a47a60adc3301106c3f27c39c0ba03e2ebe177.tar.gz
matterbridge-msglm-96a47a60adc3301106c3f27c39c0ba03e2ebe177.tar.bz2
matterbridge-msglm-96a47a60adc3301106c3f27c39c0ba03e2ebe177.zip
Add support for reloading all settings automatically after changing config except connection and gateway configuration. Closes #373
Diffstat (limited to 'bridge')
-rw-r--r--bridge/config/config.go11
1 files changed, 11 insertions, 0 deletions
diff --git a/bridge/config/config.go b/bridge/config/config.go
index 09f15c2e..1b92f83c 100644
--- a/bridge/config/config.go
+++ b/bridge/config/config.go
@@ -2,8 +2,10 @@ package config
import (
"bytes"
+ "github.com/fsnotify/fsnotify"
log "github.com/sirupsen/logrus"
"github.com/spf13/viper"
+ prefixed "github.com/x-cray/logrus-prefixed-formatter"
"os"
"strings"
"sync"
@@ -169,9 +171,13 @@ type Config struct {
}
func NewConfig(cfgfile string) *Config {
+ log.SetFormatter(&prefixed.TextFormatter{PrefixPadding: 13, DisableColors: true, FullTimestamp: false})
+ flog := log.WithFields(log.Fields{"prefix": "config"})
var cfg ConfigValues
viper.SetConfigType("toml")
+ viper.SetConfigFile(cfgfile)
viper.SetEnvPrefix("matterbridge")
+ viper.AddConfigPath(".")
viper.SetEnvKeyReplacer(strings.NewReplacer(".", "_"))
viper.AutomaticEnv()
f, err := os.Open(cfgfile)
@@ -191,6 +197,11 @@ func NewConfig(cfgfile string) *Config {
if cfg.General.MediaDownloadSize == 0 {
cfg.General.MediaDownloadSize = 1000000
}
+ viper.WatchConfig()
+ viper.OnConfigChange(func(e fsnotify.Event) {
+ flog.Println("Config file changed:", e.Name)
+ })
+
mycfg.ConfigValues = &cfg
return mycfg
}