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


Golang Logger.Errorf方法代碼示例

本文整理匯總了Golang中github.com/cloudfoundry/gosteno.Logger.Errorf方法的典型用法代碼示例。如果您正苦於以下問題:Golang Logger.Errorf方法的具體用法?Golang Logger.Errorf怎麽用?Golang Logger.Errorf使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在github.com/cloudfoundry/gosteno.Logger的用法示例。


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

示例1: NewLoggregatorClient

func NewLoggregatorClient(loggregatorAddress string, logger *gosteno.Logger, bufferSize int) LoggregatorClient {
	loggregatorClient := &udpLoggregatorClient{}

	la, err := net.ResolveUDPAddr("udp", loggregatorAddress)
	if err != nil {
		logger.Fatalf("Error resolving loggregator address %s, %s", loggregatorAddress, err)
	}

	connection, err := net.ListenPacket("udp", "")
	if err != nil {
		logger.Fatalf("Error opening udp stuff")
	}

	loggregatorClient.loggregatorAddress = la.IP.String()
	loggregatorClient.sendChannel = make(chan []byte, bufferSize)

	go func() {
		for dataToSend := range loggregatorClient.sendChannel {
			if len(dataToSend) > 0 {
				writeCount, err := connection.WriteTo(dataToSend, la)
				if err != nil {
					logger.Errorf("Writing to loggregator %s failed %s", loggregatorAddress, err)
					continue
				}
				logger.Debugf("Wrote %d bytes to %s", writeCount, loggregatorAddress)
				atomic.AddUint64(&loggregatorClient.sentMessageCount, 1)
				atomic.AddUint64(&loggregatorClient.sentByteCount, uint64(writeCount))
			} else {
				logger.Debugf("Skipped writing of 0 byte message to %s", loggregatorAddress)
			}
		}
	}()

	return loggregatorClient
}
開發者ID:KeyOfSpectator,項目名稱:gorouter,代碼行數:35,代碼來源:loggregator_client.go

示例2: connectToNatsServer

func connectToNatsServer(c *config.Config, logger *steno.Logger) yagnats.NATSConn {
	var natsClient yagnats.NATSConn
	var err error

	natsServers := c.NatsServers()
	attempts := 3
	for attempts > 0 {
		natsClient, err = yagnats.Connect(natsServers)
		if err == nil {
			break
		} else {
			attempts--
			time.Sleep(100 * time.Millisecond)
		}
	}

	if err != nil {
		logger.Errorf("Error connecting to NATS: %s\n", err)
		os.Exit(1)
	}

	natsClient.AddClosedCB(func(conn *nats.Conn) {
		logger.Errorf("Close on NATS client. nats.Conn: %+v", *conn)
		os.Exit(1)
	})

	return natsClient
}
開發者ID:jungle0755,項目名稱:gorouter,代碼行數:28,代碼來源:main.go

示例3: NewLoggregatorClient

func NewLoggregatorClient(loggregatorAddress string, logger *gosteno.Logger, bufferSize int) *udpLoggregatorClient {
	loggregatorClient := &udpLoggregatorClient{make(chan []byte, bufferSize)}

	connection, err := net.Dial("udp", loggregatorAddress)
	if err != nil {
		logger.Fatalf("Error resolving loggregator address %s, %s", loggregatorAddress, err)
		panic(err)
	}

	go func() {
		for {
			dataToSend := <-loggregatorClient.sendChannel
			if len(dataToSend) > 0 {
				writeCount, err := connection.Write(dataToSend)
				logger.Debugf("Wrote %d bytes to %s", writeCount, loggregatorAddress)
				if err != nil {
					logger.Errorf("Writing to loggregator %s failed %s", loggregatorAddress, err)
				}
			} else {
				logger.Debugf("Skipped writing of 0 byte message to %s", loggregatorAddress)
			}
		}
	}()

	return loggregatorClient
}
開發者ID:muhqu,項目名稱:gotestit,代碼行數:26,代碼來源:loggregatorclient.go

示例4: createCrypto

func createCrypto(logger *steno.Logger, secret string) *secure.AesGCM {
	// generate secure encryption key using key derivation function (pbkdf2)
	secretPbkdf2 := secure.NewPbkdf2([]byte(secret), 16)
	crypto, err := secure.NewAesGCM(secretPbkdf2)
	if err != nil {
		logger.Errorf("Error creating route service crypto: %s\n", err)
		os.Exit(1)
	}
	return crypto
}
開發者ID:idouba,項目名稱:gorouter,代碼行數:10,代碼來源:main.go

示例5: createCrypto

func createCrypto(secret string, logger *steno.Logger) *secure.AesGCM {
	secretDecoded, err := base64.StdEncoding.DecodeString(secret)
	if err != nil {
		logger.Errorf("Error decoding route service secret: %s\n", err)
		os.Exit(1)
	}

	crypto, err := secure.NewAesGCM(secretDecoded)
	if err != nil {
		logger.Errorf("Error creating route service crypto: %s\n", err)
		os.Exit(1)
	}
	return crypto
}
開發者ID:jungle0755,項目名稱:gorouter,代碼行數:14,代碼來源:main.go

示例6: setupRouteFetcher

func setupRouteFetcher(logger *steno.Logger, c *config.Config, registry rregistry.RegistryInterface) *route_fetcher.RouteFetcher {
	clock := clock.NewClock()

	tokenFetcher := newTokenFetcher(logger, clock, c)
	_, err := tokenFetcher.FetchToken(false)
	if err != nil {
		logger.Errorf("Unable to fetch token: %s", err.Error())
		os.Exit(1)
	}

	routingApiUri := fmt.Sprintf("%s:%d", c.RoutingApi.Uri, c.RoutingApi.Port)
	routingApiClient := routing_api.NewClient(routingApiUri)
	routeFetcher := route_fetcher.NewRouteFetcher(steno.NewLogger("router.route_fetcher"), tokenFetcher, registry, c, routingApiClient, 1, clock)
	return routeFetcher
}
開發者ID:idouba,項目名稱:gorouter,代碼行數:15,代碼來源:main.go

示例7: initializeClientPool

func initializeClientPool(config metronConfig, logger *gosteno.Logger) *clientpool.LoggregatorClientPool {
	adapter := storeAdapterProvider(config.EtcdUrls, config.EtcdMaxConcurrentRequests)
	err := adapter.Connect()
	if err != nil {
		logger.Errorf("Error connecting to ETCD: %v", err)
	}

	inZoneServerAddressList := servicediscovery.NewServerAddressList(adapter, "/healthstatus/doppler/"+config.Zone, logger)
	allZoneServerAddressList := servicediscovery.NewServerAddressList(adapter, "/healthstatus/doppler/", logger)

	go inZoneServerAddressList.Run(time.Duration(config.EtcdQueryIntervalMilliseconds) * time.Millisecond)
	go allZoneServerAddressList.Run(time.Duration(config.EtcdQueryIntervalMilliseconds) * time.Millisecond)

	clientPool := clientpool.NewLoggregatorClientPool(logger, config.LoggregatorDropsondePort, inZoneServerAddressList, allZoneServerAddressList)
	return clientPool
}
開發者ID:jvshahid,項目名稱:loggregator,代碼行數:16,代碼來源:main.go

示例8: sendMessagesToWebsocket

func sendMessagesToWebsocket(envelopes []*events.Envelope, websocketConnection *gorilla.Conn, logger *gosteno.Logger) {
	for _, messageEnvelope := range envelopes {
		envelopeBytes, err := proto.Marshal(messageEnvelope)
		if err != nil {
			logger.Errorf("Websocket Server %s: Error marshalling %s envelope from origin %s: %s", websocketConnection.RemoteAddr(), messageEnvelope.GetEventType().String(), messageEnvelope.GetOrigin(), err.Error())
			continue
		}

		err = websocketConnection.WriteMessage(gorilla.BinaryMessage, envelopeBytes)
		if err != nil {
			logger.Errorf("Websocket Server %s: Error when trying to send data to sink %s. Err: %v", websocketConnection.RemoteAddr(), err)
		} else {
			logger.Debugf("Websocket Server %s: Successfully sent data", websocketConnection.RemoteAddr())
		}
	}
}
開發者ID:yingkitw,項目名稱:loggregator,代碼行數:16,代碼來源:websocket_server.go

示例9: waitOnErrOrSignal

func waitOnErrOrSignal(c *config.Config, logger *steno.Logger, errChan <-chan error, router *router.Router) {
	signals := make(chan os.Signal, 1)
	signal.Notify(signals, syscall.SIGTERM, syscall.SIGINT, syscall.SIGUSR1)

	select {
	case err := <-errChan:
		if err != nil {
			logger.Errorf("Error occurred: %s", err.Error())
			os.Exit(1)
		}
	case sig := <-signals:
		go func() {
			for sig := range signals {
				logger.Infod(
					map[string]interface{}{
						"signal": sig.String(),
					},
					"gorouter.signal.ignored",
				)
			}
		}()

		if sig == syscall.SIGUSR1 {
			logger.Infod(
				map[string]interface{}{
					"timeout": (c.DrainTimeout).String(),
				},
				"gorouter.draining",
			)

			router.Drain(c.DrainTimeout)
		}

		stoppingAt := time.Now()

		logger.Info("gorouter.stopping")

		router.Stop()

		logger.Infod(
			map[string]interface{}{
				"took": time.Since(stoppingAt).String(),
			},
			"gorouter.stopped",
		)
	}
}
開發者ID:jungle0755,項目名稱:gorouter,代碼行數:47,代碼來源:main.go

示例10: newTokenFetcher

func newTokenFetcher(logger *steno.Logger, clock clock.Clock, c *config.Config) token_fetcher.TokenFetcher {
	if c.RoutingApi.AuthDisabled {
		logger.Info("using noop token fetcher")
		return token_fetcher.NewNoOpTokenFetcher()
	}
	tokenFetcherConfig := token_fetcher.TokenFetcherConfig{
		MaxNumberOfRetries:   c.TokenFetcherMaxRetries,
		RetryInterval:        c.TokenFetcherRetryInterval,
		ExpirationBufferTime: c.TokenFetcherExpirationBufferTimeInSeconds,
	}
	cfLogger, _ := cf_lager.New("token_fetcher")
	tokenFetcher, err := token_fetcher.NewTokenFetcher(cfLogger, &c.OAuth, tokenFetcherConfig, clock)
	if err != nil {
		logger.Errorf("Error creating token fetcher: %s\n", err)
		os.Exit(1)
	}
	logger.Info("using uaa token fetcher")
	return tokenFetcher
}
開發者ID:idouba,項目名稱:gorouter,代碼行數:19,代碼來源:main.go

示例11: NewElector

func NewElector(instanceName string, adapter storeadapter.StoreAdapter, updateInterval time.Duration, logger *gosteno.Logger) *Elector {
	for {
		err := adapter.Connect()

		if err == nil {
			break
		}

		logger.Errorf("Elector: Unable to connect to store: '%s'", err.Error())
		time.Sleep(updateInterval)
	}

	return &Elector{
		instanceName:   []byte(instanceName),
		adapter:        adapter,
		updateInterval: updateInterval,
		logger:         logger,
	}
}
開發者ID:lyuyun,項目名稱:loggregator,代碼行數:19,代碼來源:elector.go

示例12: sendMessagesToWebsocket

func sendMessagesToWebsocket(endpoint string, envelopes []*events.Envelope, websocketConnection *gorilla.Conn, batcher Batcher, logger *gosteno.Logger) {
	for _, messageEnvelope := range envelopes {
		envelopeBytes, err := proto.Marshal(messageEnvelope)
		if err != nil {
			logger.Errorf("Websocket Server %s: Error marshalling %s envelope from origin %s: %s", websocketConnection.RemoteAddr(), messageEnvelope.GetEventType().String(), messageEnvelope.GetOrigin(), err.Error())
			continue
		}

		err = websocketConnection.WriteMessage(gorilla.BinaryMessage, envelopeBytes)
		if err != nil {
			logger.Errorf("Websocket Server %s: Error when trying to send data to sink %s. Err: %v", websocketConnection.RemoteAddr(), err)
			continue
		}
		batcher.BatchCounter("sentEnvelopes").
			SetTag("protocol", "ws").
			SetTag("event_type", messageEnvelope.GetEventType().String()).
			SetTag("endpoint", endpoint).
			Increment()

		logger.Debugf("Websocket Server %s: Successfully sent data", websocketConnection.RemoteAddr())
	}
}
開發者ID:kei-yamazaki,項目名稱:loggregator,代碼行數:22,代碼來源:websocket_server.go

示例13: NewUDPClient

func NewUDPClient(logger *gosteno.Logger, address string, bufferSize int) (Client, error) {
	loggregatorClient := &udpClient{
		address: address,
	}

	la, err := net.ResolveUDPAddr("udp", address)
	if err != nil {
		return nil, err
	}

	connection, err := net.ListenPacket("udp", "")
	if err != nil {
		return nil, err
	}

	loggregatorClient.sendChannel = make(chan []byte, bufferSize)
	loggregatorClient.doneChannel = make(chan struct{})

	go func() {
		for dataToSend := range loggregatorClient.sendChannel {
			if len(dataToSend) == 0 {
				logger.Debugf("Skipped writing of 0 byte message to %s", address)
				continue
			}

			writeCount, err := connection.WriteTo(dataToSend, la)
			if err != nil {
				logger.Errorf("Writing to loggregator %s failed %s", address, err)
				continue
			}
			logger.Debugf("Wrote %d bytes to %s", writeCount, address)
		}

		close(loggregatorClient.doneChannel)
	}()

	return loggregatorClient, nil
}
開發者ID:pkdevbox,項目名稱:loggregatorlib,代碼行數:38,代碼來源:udpclient.go


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