Esempio n. 1
0
func loadConfig(app *App) error {
	data, err := ioutil.ReadFile(app.Config.File)
	if err == nil {
		err = json.Unmarshal(data, app.Config)
	}
	if len(app.Config.LogLevelName) == 0 {
		app.Config.LogLevelName = "listen"
	}
	level, ok := logger.LogLevel[app.Config.LogLevelName]
	if !ok {
		logger.MustError("loglevel=\"%s\" in %s is invalid; using \"%s\"",
			app.Config.LogLevelName, app.Config.File, "debug")
		app.Config.LogLevelName = "debug"
		app.Config.LogLevel = logger.Debug
	} else {
		app.Config.LogLevel = level
	}
	return err
}
Esempio n. 2
0
func initConfig(config *Config) *Config {
	if config == nil {
		config = new(Config)
	}
	if len(config.group) == 0 {
		config.group = group
	}
	if len(config.LogLevel) == 0 {
		config.LogLevel = "listen"
	}
	if level, ok := logger.LogLevel[config.LogLevel]; !ok {
		logger.MustError("LogLevel=\"%s\" is invalid; using \"%s\" [%d]",
			config.LogLevel, "debug", errLogLevel)
		config.LogLevel = "debug"
		config.logLevel = logger.Debug
	} else {
		config.logLevel = level
	}
	return config
}