當前位置: 首頁>>代碼示例>>Golang>>正文


Golang logger.Logger類代碼示例

本文整理匯總了Golang中github.com/cloudfoundry/hm9000/helpers/logger.Logger的典型用法代碼示例。如果您正苦於以下問題:Golang Logger類的具體用法?Golang Logger怎麽用?Golang Logger使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了Logger類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: ServeAPI

func ServeAPI(l logger.Logger, conf *config.Config) {
	store := connectToStore(l, conf)

	apiHandler, err := handlers.New(l, store, buildTimeProvider(l))
	if err != nil {
		l.Error("initialize-handler.failed", err)
		panic(err)
	}
	handler := handlers.BasicAuthWrap(apiHandler, conf.APIServerUsername, conf.APIServerPassword)

	listenAddr := fmt.Sprintf("%s:%d", conf.APIServerAddress, conf.APIServerPort)

	members := grouper.Members{
		{"api", http_server.New(listenAddr, handler)},
	}

	group := grouper.NewOrdered(os.Interrupt, members)

	monitor := ifrit.Invoke(sigmon.New(group))

	l.Info("started")
	l.Info(listenAddr)

	err = <-monitor.Wait()
	if err != nil {
		l.Error("exited", err)
		os.Exit(1)
	}

	l.Info("exited")
	os.Exit(0)
}
開發者ID:cgrotz,項目名稱:hm9000,代碼行數:32,代碼來源:serve_api.go

示例2: connectToMessageBus

func connectToMessageBus(l logger.Logger, conf *config.Config) yagnats.NATSClient {
	members := []yagnats.ConnectionProvider{}

	for _, natsConf := range conf.NATS {
		members = append(members, &yagnats.ConnectionInfo{
			Addr: fmt.Sprintf("%s:%d", natsConf.Host, natsConf.Port),

			Username: natsConf.User,
			Password: natsConf.Password,
		})
	}

	connectionInfo := &yagnats.ConnectionCluster{
		Members: members,
	}

	natsClient := yagnats.NewClient()

	err := natsClient.Connect(connectionInfo)

	if err != nil {
		l.Error("Failed to connect to the message bus", err)
		os.Exit(1)
	}

	return natsClient
}
開發者ID:tomzhang,項目名稱:golang-devops-stuff,代碼行數:27,代碼來源:common.go

示例3: ServeMetrics

func ServeMetrics(steno *gosteno.Logger, l logger.Logger, conf *config.Config) {
	store := connectToStore(l, conf)
	messageBus := connectToMessageBus(l, conf)

	acquireLock(l, conf, "metrics-server")

	collectorRegistrar := collectorregistrar.NewCollectorRegistrar(messageBus, steno)

	metricsServer := metricsserver.New(
		collectorRegistrar,
		steno,
		metricsaccountant.New(store),
		l,
		store,
		buildTimeProvider(l),
		conf,
	)

	err := metricsServer.Start()
	if err != nil {
		l.Error("Failed to serve metrics", err)
	}
	l.Info("Serving Metrics")
	select {}
}
開發者ID:cgrotz,項目名稱:hm9000,代碼行數:25,代碼來源:serve_metrics.go

示例4: connectToStore

func connectToStore(l logger.Logger, conf *config.Config) (store.Store, metricsaccountant.UsageTracker) {
	if conf.StoreType == "etcd" || conf.StoreType == "ZooKeeper" {
		adapter, workerPool := connectToStoreAdapter(l, conf)
		return store.NewStore(conf, adapter, l), workerPool
	} else {
		l.Error(fmt.Sprintf("Unknown store type %s.  Choose one of 'etcd' or 'ZooKeeper'", conf.StoreType), fmt.Errorf("Unkown store type"))
		os.Exit(1)
	}

	return nil, nil
}
開發者ID:karlpilkington,項目名稱:golang-devops-stuff,代碼行數:11,代碼來源:common.go

示例5: buildClock

func buildClock(l logger.Logger) clock.Clock {
	if os.Getenv("HM9000_FAKE_TIME") == "" {
		return clock.NewClock()
	} else {
		timestamp, err := strconv.Atoi(os.Getenv("HM9000_FAKE_TIME"))
		if err != nil {
			l.Error("Failed to load timestamp", err)
			os.Exit(1)
		}
		return NewFixedClock(time.Unix(int64(timestamp), 0))
	}
}
開發者ID:nagyistge,項目名稱:hm9000,代碼行數:12,代碼來源:common.go

示例6: connectToStoreAdapter

func connectToStoreAdapter(l logger.Logger, conf *config.Config) (storeadapter.StoreAdapter, metricsaccountant.UsageTracker) {
	var adapter storeadapter.StoreAdapter
	workerPool := workerpool.NewWorkerPool(conf.StoreMaxConcurrentRequests)
	adapter = etcdstoreadapter.NewETCDStoreAdapter(conf.StoreURLs, workerPool)
	err := adapter.Connect()
	if err != nil {
		l.Error("Failed to connect to the store", err)
		os.Exit(1)
	}

	return adapter, workerPool
}
開發者ID:tomzhang,項目名稱:golang-devops-stuff,代碼行數:12,代碼來源:common.go

示例7: StartEvacuator

func StartEvacuator(l logger.Logger, conf *config.Config) {
	messageBus := connectToMessageBus(l, conf)
	store, _ := connectToStore(l, conf)

	acquireLock(l, conf, "evacuator")

	evacuator := evacuatorpackage.New(messageBus, store, buildTimeProvider(l), conf, l)

	evacuator.Listen()
	l.Info("Listening for DEA Evacuations")
	select {}
}
開發者ID:KeyOfSpectator,項目名稱:hm9000,代碼行數:12,代碼來源:start_evacuator.go

示例8: acquireLock

func acquireLock(l logger.Logger, conf *config.Config, lockName string) {
	adapter, _ := connectToStoreAdapter(l, conf)
	l.Info("Acquiring lock for " + lockName)

	lock := storeadapter.StoreNode{
		Key: "/hm/locks/" + lockName,
		TTL: 10,
	}

	status, _, err := adapter.MaintainNode(lock)
	if err != nil {
		l.Error("Failed to talk to lock store", err)
		os.Exit(1)
	}

	lockAcquired := make(chan bool)

	go func() {
		for {
			if <-status {
				if lockAcquired != nil {
					close(lockAcquired)
					lockAcquired = nil
				}
			} else {
				l.Error("Lost the lock", errors.New("Lost the lock"))
				os.Exit(197)
			}
		}
	}()

	<-lockAcquired
	l.Info("Acquired lock for " + lockName)
}
開發者ID:tomzhang,項目名稱:golang-devops-stuff,代碼行數:34,代碼來源:common.go

示例9: buildTimeProvider

func buildTimeProvider(l logger.Logger) timeprovider.TimeProvider {
	if os.Getenv("HM9000_FAKE_TIME") == "" {
		return timeprovider.NewTimeProvider()
	} else {
		timestamp, err := strconv.Atoi(os.Getenv("HM9000_FAKE_TIME"))
		if err != nil {
			l.Error("Failed to load timestamp", err)
			os.Exit(1)
		}
		return &faketimeprovider.FakeTimeProvider{
			TimeToProvide: time.Unix(int64(timestamp), 0),
		}
	}
}
開發者ID:tomzhang,項目名稱:golang-devops-stuff,代碼行數:14,代碼來源:common.go

示例10: StartListeningForActual

func StartListeningForActual(l logger.Logger, c *cli.Context) {
	conf := loadConfig(l, c)
	messageBus := connectToMessageBus(l, conf)
	store := connectToStore(l, conf)

	listener := actualstatelistener.New(conf,
		messageBus,
		store,
		timeprovider.NewTimeProvider(),
		l)

	listener.Start()
	l.Info("Listening for Actual State", nil)
	select {}
}
開發者ID:Zhann,項目名稱:hm9000,代碼行數:15,代碼來源:start_listening_for_actual.go

示例11: connectToStoreAdapter

func connectToStoreAdapter(l logger.Logger, conf *config.Config, usage *usageTracker) storeadapter.StoreAdapter {
	var adapter storeadapter.StoreAdapter
	var around workpool.AroundWork = workpool.DefaultAround
	if usage != nil {
		around = usage
	}
	workPool := workpool.New(conf.StoreMaxConcurrentRequests, 0, around)
	adapter = etcdstoreadapter.NewETCDStoreAdapter(conf.StoreURLs, workPool)
	err := adapter.Connect()
	if err != nil {
		l.Error("Failed to connect to the store", err)
		os.Exit(1)
	}

	return adapter
}
開發者ID:cgrotz,項目名稱:hm9000,代碼行數:16,代碼來源:common.go

示例12: connectToStoreAdapter

func connectToStoreAdapter(l logger.Logger, conf *config.Config) (storeadapter.StoreAdapter, metricsaccountant.UsageTracker) {
	var adapter storeadapter.StoreAdapter
	workerPool := workerpool.NewWorkerPool(conf.StoreMaxConcurrentRequests)
	if conf.StoreType == "etcd" {
		adapter = etcdstoreadapter.NewETCDStoreAdapter(conf.StoreURLs, workerPool)
	} else if conf.StoreType == "ZooKeeper" {
		adapter = zookeeperstoreadapter.NewZookeeperStoreAdapter(conf.StoreURLs, workerPool, buildTimeProvider(l), time.Second)
	} else {
		l.Error(fmt.Sprintf("Unknown store type %s.  Choose one of 'etcd' or 'ZooKeeper'", conf.StoreType), fmt.Errorf("Unkown store type"))
		os.Exit(1)
	}
	err := adapter.Connect()
	if err != nil {
		l.Error("Failed to connect to the store", err)
		os.Exit(1)
	}

	return adapter, workerPool
}
開發者ID:karlpilkington,項目名稱:golang-devops-stuff,代碼行數:19,代碼來源:common.go

示例13: StartListeningForActual

func StartListeningForActual(l logger.Logger, conf *config.Config) {
	messageBus := connectToMessageBus(l, conf)
	store, usageTracker := connectToStoreAndTrack(l, conf)

	acquireLock(l, conf, "listener")

	listener := actualstatelistener.New(conf,
		messageBus,
		store,
		usageTracker,
		metricsaccountant.New(store),
		buildClock(l),
		l,
	)

	listener.Start()
	l.Info("Listening for Actual State")
	select {}
}
開發者ID:nagyistge,項目名稱:hm9000,代碼行數:19,代碼來源:start_listening_for_actual.go

示例14: ServeAPI

func ServeAPI(l logger.Logger, conf *config.Config) {
	store, _ := connectToStore(l, conf)
	messageBus := connectToMessageBus(l, conf)

	//no locking necessary for the api server.  it's ok to have multiples of these running.
	//NATS will distribute the requests and ensure that only one api-server handles a given request
	//because we use a NATS queue.

	apiServer := apiserver.New(
		messageBus,
		store,
		buildTimeProvider(l),
		l,
	)

	apiServer.Listen()
	l.Info(fmt.Sprintf("Serving API over NATS (subject: app.state)"))
	select {}
}
開發者ID:nkts,項目名稱:golang-devops-stuff,代碼行數:19,代碼來源:serve_api.go

示例15: Daemonize

func Daemonize(
	component string,
	callback func() error,
	period time.Duration,
	timeout time.Duration,
	logger logger.Logger,
	adapter storeadapter.StoreAdapter,
) error {
	logger.Info("Acquiring lock for " + component)

	lostLockChannel, releaseLockChannel, err := adapter.GetAndMaintainLock(component, 10)
	if err != nil {
		logger.Info(fmt.Sprintf("Failed to acquire lock: %s", err))
		return err
	}

	go func() {
		<-lostLockChannel
		logger.Error("Lost the lock", errors.New("Lock the lock"))
		os.Exit(197)
	}()

	logger.Info("Acquired lock for " + component)

	logger.Info(fmt.Sprintf("Running Daemon every %d seconds with a timeout of %d", int(period.Seconds()), int(timeout.Seconds())))

	for {
		afterChan := time.After(period)
		timeoutChan := time.After(timeout)
		errorChan := make(chan error, 1)

		t := time.Now()

		go func() {
			errorChan <- callback()
		}()

		select {
		case err := <-errorChan:
			logger.Info("Daemonize Time", map[string]string{
				"Component": component,
				"Duration":  fmt.Sprintf("%.4f", time.Since(t).Seconds()),
			})
			if err != nil {
				logger.Error("Daemon returned an error. Continuining...", err)
			}
		case <-timeoutChan:
			releaseLockChannel <- true
			return errors.New("Daemon timed out. Aborting!")
		}

		<-afterChan
	}

	return nil
}
開發者ID:johntdyer,項目名稱:golang-devops-stuff,代碼行數:56,代碼來源:daemon.go


注:本文中的github.com/cloudfoundry/hm9000/helpers/logger.Logger類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。