+/**Dynamic log-level changes **/
+
+func loadConfig() {
+ viper.SetConfigFile(parseCmd())
+ if err := viper.ReadInConfig(); err != nil {
+ Log.Errorf("Error reading config file, %s", err)
+ }
+ Log.Infof("Using config file: %s\n", viper.ConfigFileUsed())
+ // Watch for config file changes and re-read data ...
+ watch()
+}
+func parseCmd() string {
+ var fileName *string
+ fileName = flag.String("f", DEFAULT_CONFIG_FILE, "Specify the configuration file.")
+ flag.String("port", DEFAULT_PORT, "Specify the port file.")
+ flag.Parse()
+
+ return *fileName
+}
+
+func watch() {
+ viper.WatchConfig()
+ viper.OnConfigChange(func(e fsnotify.Event) {
+ Log.Infof("config file changed %s", e.Name)
+ setLoglevel()
+ })
+}
+
+/*********MDC LOG CHNAGES ********/
+func setLoglevel() {
+ var loglevel int
+ if err := viper.UnmarshalKey("loglevel", &loglevel); err != nil {
+ Log.Errorf("Unmarshalling failed while reading %d", loglevel)
+ }
+
+ switch loglevel {
+ case 1:
+ Log.Infof("LOGLEVEL is set to ERROR\n")
+ case 2:
+ Log.Infof("LOGLEVEL is set to WARNING\n")
+ case 3:
+ Log.Infof("LOGLEVEL is set to INFO\n")
+ case 4:
+ Log.Infof("LOGLEVEL is set to DEBUG\n")
+ }
+ Log.SetLevel(loglevel)
+}
+