浏览代码

Log to default log directory, only if custom configuration failed. (#5393)

Andris Raugulis 9 年之前
父节点
当前提交
1c293781e3
共有 1 个文件被更改,包括 9 次插入8 次删除
  1. 9 8
      pkg/setting/setting.go

+ 9 - 8
pkg/setting/setting.go

@@ -284,19 +284,19 @@ func evalConfigValues() {
 	}
 }
 
-func loadSpecifedConfigFile(configFile string) {
+func loadSpecifedConfigFile(configFile string) error {
 	if configFile == "" {
 		configFile = filepath.Join(HomePath, "conf/custom.ini")
 		// return without error if custom file does not exist
 		if !pathExists(configFile) {
-			return
+			return nil
 		}
 	}
 
 	userConfig, err := ini.Load(configFile)
 	userConfig.BlockMode = false
 	if err != nil {
-		log.Fatal(3, "Failed to parse %v, %v", configFile, err)
+		return fmt.Errorf("Failed to parse %v, %v", configFile, err)
 	}
 
 	for _, section := range userConfig.Sections() {
@@ -318,6 +318,7 @@ func loadSpecifedConfigFile(configFile string) {
 	}
 
 	configFiles = append(configFiles, configFile)
+	return nil
 }
 
 func loadConfiguration(args *CommandLineArgs) {
@@ -339,12 +340,12 @@ func loadConfiguration(args *CommandLineArgs) {
 	// load default overrides
 	applyCommandLineDefaultProperties(commandLineProps)
 
-	// init logging before specific config so we can log errors from here on
-	DataPath = makeAbsolute(Cfg.Section("paths").Key("data").String(), HomePath)
-	initLogging()
-
 	// load specified config file
-	loadSpecifedConfigFile(args.Config)
+	err = loadSpecifedConfigFile(args.Config)
+	if err != nil {
+		initLogging()
+		log.Fatal(3, err.Error())
+	}
 
 	// apply environment overrides
 	applyEnvVariableOverrides()