// Init 从 config.Config 中初始化整个 logs 系统
355567
func (logs *Logs) Init(cfg *config.Config) error {
	for name, c := range cfg.Items {
		index, found := levels[name]
		if !found {
			panic("未知的二级元素名称:" + name)
		}

		l, err := toWriter(name, c)
		if err != nil {
			return err
		}

		logs.loggers[index] = l.(*logger)
	}

	return nil
}
70003
func (p *HelloWorld) Init() error {
	p.Log.Debug("Loading config..")
	// Load config file.
	cfg := defaultConfig()
	found, err := p.Cfg.LoadValue(cfg)
	if err != nil {
		return err
	} else if !found {
		p.Log.Warnf("config not found")
	}

	p.Log.Info(cfg.Greeting)
	return nil
}
819162
func (sys *ConfigSys) Init(objAPI ObjectLayer) error {
	if objAPI == nil {
		return errInvalidArgument
	}

	doneCh := make(chan struct{})
	defer close(doneCh)

	// Initializing configuration needs a retry mechanism for
	// the following reasons:
	//  - Read quorum is lost just after the initialization
	//    of the object layer.
	//  - Write quorum not met when upgrading configuration
	//    version is needed.
	for range newRetryTimerSimple(doneCh) {
		if err := initConfig(objAPI); err != nil {
			if strings.Contains(err.Error(), InsufficientReadQuorum{}.Error()) ||
				strings.Contains(err.Error(), InsufficientWriteQuorum{}.Error()) {
				logger.Info("Waiting for configuration to be initialized..")
				continue
			}
			return err
		}
		break
	}
	return nil
}
804485
func (c *Config) Open(logger log.Logger) (storage.Storage, error) {
	return New(logger), nil
}
544097
func (l *JSONLogger) InitLogger() error {
	if len(l.config.HostURI) == 0 {
		return fmt.Errorf("A HostURI must be set")
	}
	hostURL, err := url.Parse(l.config.HostURI)
	if err != nil {
		return fmt.Errorf("Invalid HostURI: %v", err)
	}
	if !strings.Contains(hostURL.Host, ":") {
		return fmt.Errorf("A port must be provided")
	}
	l.hostURL = hostURL

	l.unprefixedMap = make(map[string]bool)
	for _, fieldName := range l.config.UnprefixedFields {
		l.unprefixedMap[fieldName] = true
	}

	if err := l.connect(); err != nil {
		if !l.config.AllowDisconnectedInit {
			return err
		}

		// Reconnect in background
		l.performReconnect()
	}

	l.isInitialized = true
	return nil
}
236571
func Init(c *config.Config) (*Service, error) {
	return &Service{Config: c}, nil
}
885510
func (c *configCommand) Init(args []string) error {
	// If there are arguments provided to reset, we turn it into a slice of
	// strings and verify them. If there is one or more valid keys to reset and
	// no other errors initializing the command, c.resetDefaults will be called
	// in c.Run.
	if err := c.parseResetKeys(); err != nil {
		return errors.Trace(err)
	}

	switch len(args) {
	case 0:
		return c.handleZeroArgs()
	case 1:
		return c.handleOneArg(args[0])
	default:
		return c.handleArgs(args)
	}
}
670739
func initConfig() {
	if cfgFile != "" { // enable ability to specify config file via flag
		viper.SetConfigFile(cfgFile)
	}

	viper.SetConfigName(".alm-test.yml") // name of config file (without extension)
	viper.AddConfigPath("$HOME")  	 // adding home directory as first search path
	viper.AutomaticEnv()          	 // read in environment variables that match

	// If a config file is found, read it in.
	if err := viper.ReadInConfig(); err == nil {
		fmt.Println("Using config file:", viper.ConfigFileUsed())
	}
}
1364081
func initialize() {
	defaultLogger = &Logger{
		infoLog:    log.New(os.Stderr, initText+tagInfo, flags),
		warningLog: log.New(os.Stderr, initText+tagWarning, flags),
		errorLog:   log.New(os.Stderr, initText+tagError, flags),
		fatalLog:   log.New(os.Stderr, initText+tagFatal, flags),
	}
}
1317629
func (g *Git) InitConfig(ctx context.Context, userName, userEmail string) error {
	if userName == "" || userEmail == "" || !strings.Contains(userEmail, "@") {
		return fmt.Errorf("username and email must not be empty and valid")
	}
	// set commit identity
	if err := g.ConfigSet(ctx, "user.name", userName); err != nil {
		return errors.Wrapf(err, "failed to set git config user.name")
	}
	if err := g.ConfigSet(ctx, "user.email", userEmail); err != nil {
		return errors.Wrapf(err, "failed to set git config user.email")
	}

	// ensure sane git config
	if err := g.fixConfig(ctx); err != nil {
		return errors.Wrapf(err, "failed to fix git config")
	}

	if err := ioutil.WriteFile(filepath.Join(g.path, ".gitattributes"), []byte("*.gpg diff=gpg\n"), fileMode); err != nil {
		return errors.Errorf("Failed to initialize git: %s", err)
	}
	if err := g.Add(ctx, g.path+"/.gitattributes"); err != nil {
		out.Yellow(ctx, "Warning: Failed to add .gitattributes to git")
	}
	if err := g.Commit(ctx, "Configure git repository for gpg file diff."); err != nil {
		out.Yellow(ctx, "Warning: Failed to commit .gitattributes to git")
	}

	return nil
}
605869
func initConfig() {
	// Initialize
	logger := log.New("armor")
	colorer := color.New()
	logger.SetLevel(log.INFO)
	colorer.SetOutput(logger.Output())
	stdLog.SetOutput(logger.Output())
	a := &armor.Armor{
		Logger:  logger,
		Colorer: colorer,
	}

	// Root dir
	dir, err := homedir.Dir()
	if err != nil {
		logger.Fatalf("Failed to find the home directory: %v", err)
	}
	a.RootDir = filepath.Join(dir, ".armor")
	if err = os.MkdirAll(a.RootDir, 0755); err != nil {
		logger.Fatalf("Failed to create root directory: %v", err)
	}

	// Config
	if configFile == "" {
		configFile = filepath.Join(a.RootDir, "config.yaml")
	}
	data, err := ioutil.ReadFile(configFile)
	if err != nil {
		a.DefaultConfig = true
		// Use default config
		data = []byte(fmt.Sprintf(defaultConfig, net.JoinHostPort("", port), root))
	}
	if err = yaml.Unmarshal(data, a); err != nil {
		logger.Fatalf("Failed to parse the config file: %v", err)
	}

	// Defaults
	if a.Address == "" {
		a.Address = ":80"
	}
	if a.Storm == nil {
		a.Storm = &armor.Storm{
			URI: filepath.Join(a.RootDir, "storm.db"),
		}
	}
	if a.Admin == nil {
		a.Admin = &armor.Admin{
			Address: "localhost:8081",
		}
	}
	if a.Cluster == nil {
		a.Cluster = &armor.Cluster{
			Address: ":8082",
			Peers:   []string{"localhost:8082"},
		}
	}
	if a.Hosts == nil {
		a.Hosts = make(armor.Hosts)
	}

	// HTTP
	h := a.NewHTTP()

	// Store
	if a.Postgres != nil {
		a.Store = store.NewPostgres(a.Postgres.URI)
	} else {
		if a.Store, err = store.NewStorm(a.Storm.URI); err != nil {
			logger.Fatalf("Failed to connect to storm: %v", err)
		}
	}
	defer a.Store.Close()
	a.SavePlugins()

	// Start cluster
	go a.StartCluster()

	// Start admin
	go admin.Start(a)

	// Create tunnel
	if expose {
		go h.CreateTunnel()
	}

	// Start server
	colorer.Printf(banner, colorer.Red("v"+armor.Version), colorer.Blue(armor.Website))
	if a.TLS != nil {
		go func() {
			logger.Fatal(h.StartTLS())
		}()
	}
	logger.Fatal(h.Start())
}
1043929
func (s *Storage) Config(c context.Context, cfg storage.Config) error {
	return s.run(func() error {
		s.MaxLogAge = cfg.MaxLogAge
		return nil
	})
}
165794
func init() {
	wallet.UseLogger(walletLog)
	wtxmgr.UseLogger(txmgrLog)
	chain.UseLogger(chainLog)
	rpcclient.UseLogger(chainLog)
	rpcserver.UseLogger(grpcLog)
	legacyrpc.UseLogger(legacyRPCLog)
	neutrino.UseLogger(btcnLog)
}
556702
func InitLog() error {

	var err error

	// init logger
	LogAccess = logrus.New()
	LogError = logrus.New()

	LogAccess.Formatter = &logrus.TextFormatter{
		TimestampFormat: "2006/01/02 - 15:04:05",
		FullTimestamp:   true,
	}

	LogError.Formatter = &logrus.TextFormatter{
		TimestampFormat: "2006/01/02 - 15:04:05",
		FullTimestamp:   true,
	}

	// set logger
	if err = SetLogLevel(LogAccess, PushConf.Log.AccessLevel); err != nil {
		return errors.New("Set access log level error: " + err.Error())
	}

	if err = SetLogLevel(LogError, PushConf.Log.ErrorLevel); err != nil {
		return errors.New("Set error log level error: " + err.Error())
	}

	if err = SetLogOut(LogAccess, PushConf.Log.AccessLog); err != nil {
		return errors.New("Set access log path error: " + err.Error())
	}

	if err = SetLogOut(LogError, PushConf.Log.ErrorLog); err != nil {
		return errors.New("Set error log path error: " + err.Error())
	}

	return nil
}
453748
func init() {
	log.Out = os.Stdout
	if debug {
		log.Level = logger.DebugLevel
	}
}
516388
func init() {
	log = logger.New()
	log.Out = os.Stdout
	log.Level = logger.DebugLevel
}
744058
func InitConfig(filepath string, section string) Config {
	c, err := InitEdgeRc(filepath, section)
	if err != nil {
		log.Panic(err.Error())
	}

	return c
}