/
loadConfig.go
43 lines (37 loc) · 971 Bytes
/
loadConfig.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
package main
import (
"github.com/op/go-logging"
"github.com/spf13/viper"
"os"
)
func loadConfig(filenamePath *string, filename *string) {
log := logging.MustGetLogger("log")
viper.SetConfigName(*filename)
viper.AddConfigPath(*filenamePath)
if err := viper.ReadInConfig(); err != nil {
log.Critical("Unable to load config file:", err)
os.Exit(1)
}
switch viper.GetString("logtype") {
case "critical":
logging.SetLevel(0, "")
case "error":
logging.SetLevel(1, "")
case "warning":
logging.SetLevel(2, "")
case "notice":
logging.SetLevel(3, "")
case "info":
logging.SetLevel(4, "")
case "debug":
logging.SetLevel(5, "")
log.Debug("\"debug\" is selected")
default:
logging.SetLevel(2, "")
//log.Debug("\"default\" is selected (warning)")
}
log.Debug("loadConfig func:")
log.Debug(" path: %s", *filenamePath)
log.Debug(" filename: %s", *filename)
log.Debug(" logtype in file config is \"%s\"", viper.GetString("logtype"))
}