fix(logging): fixed reading config level from config file, fixes #5079

This commit is contained in:
Torkel Ödegaard 2016-05-18 14:18:08 +02:00
parent cd80884b76
commit d474eba53a

View File

@ -526,6 +526,17 @@ var logLevels = map[string]int{
"Critical": 5, "Critical": 5,
} }
func getLogLevel(key string, defaultName string) (string, int) {
levelName := Cfg.Section(key).Key("level").In(defaultName, []string{"Trace", "Debug", "Info", "Warn", "Error", "Critical"})
level, ok := logLevels[levelName]
if !ok {
log.Fatal(4, "Unknown log level: %s", levelName)
}
return levelName, level
}
func initLogging(args *CommandLineArgs) { func initLogging(args *CommandLineArgs) {
//close any existing log handlers. //close any existing log handlers.
log.Close() log.Close()
@ -533,8 +544,12 @@ func initLogging(args *CommandLineArgs) {
LogModes = strings.Split(Cfg.Section("log").Key("mode").MustString("console"), ",") LogModes = strings.Split(Cfg.Section("log").Key("mode").MustString("console"), ",")
LogsPath = makeAbsolute(Cfg.Section("paths").Key("logs").String(), HomePath) LogsPath = makeAbsolute(Cfg.Section("paths").Key("logs").String(), HomePath)
defaultLevelName, _ := getLogLevel("log", "Info")
LogConfigs = make([]util.DynMap, len(LogModes)) LogConfigs = make([]util.DynMap, len(LogModes))
for i, mode := range LogModes { for i, mode := range LogModes {
mode = strings.TrimSpace(mode) mode = strings.TrimSpace(mode)
sec, err := Cfg.GetSection("log." + mode) sec, err := Cfg.GetSection("log." + mode)
if err != nil { if err != nil {
@ -542,12 +557,7 @@ func initLogging(args *CommandLineArgs) {
} }
// Log level. // Log level.
levelName := Cfg.Section("log."+mode).Key("level").In("Trace", _, level := getLogLevel("log."+mode, defaultLevelName)
[]string{"Trace", "Debug", "Info", "Warn", "Error", "Critical"})
level, ok := logLevels[levelName]
if !ok {
log.Fatal(4, "Unknown log level: %s", levelName)
}
// Generate log configuration. // Generate log configuration.
switch mode { switch mode {