+const GeneralKeyDefaultValue = "{\"enableRic\":true}"
+const DEFAULT_CONFIG_FILE = "../resources/configuration.yaml"
+const DEFAULT_PORT = "8080"
+var Log *logger.Logger
+
+func initKeys(logger *logger.Logger, sdl *sdlgo.SyncStorage) error {
+ ok, err := sdl.SetIfNotExists(common.GetRNibNamespace(), common.BuildGeneralConfigurationKey(), GeneralKeyDefaultValue)
+
+ if err != nil {
+ logger.Errorf("#app.main - Failed setting GENERAL key")
+ return err
+ }
+
+ if ok {
+ logger.Infof("#app.main - Successfully set GENERAL key")
+ } else {
+ logger.Infof("#app.main - GENERAL key exists, no need to set")
+ }
+
+ return nil
+
+}
+/**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)
+}
+
+