当前位置: 首页>>代码示例>>Golang>>正文


Golang Logger.Error方法代码示例

本文整理汇总了Golang中github.com/koding/logging.Logger.Error方法的典型用法代码示例。如果您正苦于以下问题:Golang Logger.Error方法的具体用法?Golang Logger.Error怎么用?Golang Logger.Error使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在github.com/koding/logging.Logger的用法示例。


在下文中一共展示了Logger.Error方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: NewMultiInstances

// NewMultiInstances fetches EC2 instance list from each region.
func NewMultiInstances(clients *amazon.Clients, log logging.Logger) *MultiInstances {
	if log == nil {
		log = defaultLogger
	}
	var m = newMultiInstances()
	var wg sync.WaitGroup
	var mu sync.Mutex // protects m.m
	for region, client := range clients.Regions() {
		wg.Add(1)
		go func(region string, client *amazon.Client) {
			defer wg.Done()
			instances, err := client.Instances()
			if err != nil {
				log.Error("[%s] fetching instances error: %s", region, err)
				return
			}
			log.Info("[%s] fetched %d instances", region, len(instances))
			i := make(Instances, len(instances))
			for _, instance := range instances {
				i[aws.StringValue(instance.InstanceId)] = instance
			}
			var ok bool
			mu.Lock()
			if _, ok = m.m[client]; !ok {
				m.m[client] = i
			}
			mu.Unlock()
			if ok {
				panic(fmt.Errorf("[%s] duplicated client=%p: %+v", region, client, i))
			}
		}(region, client)
	}
	wg.Wait()
	return m
}
开发者ID:koding,项目名称:koding,代码行数:36,代码来源:multiinstances.go

示例2: NewMachine

// NewMachine initializes a new Machine struct with any internal vars created.
func NewMachine(meta MachineMeta, log logging.Logger, t Transport) (*Machine, error) {
	log = MachineLogger(meta, log)

	// Create our Pingers, to be used in the PingTrackers
	kitePinger := kitepinger.NewKitePinger(t)
	httpPinger, err := kitepinger.NewKiteHTTPPinger(meta.URL)
	if err != nil {
		log.Error(
			"Unable to create HTTPPinger from meta.URL. url:%s, err:%s", meta.URL, err,
		)
		return nil, err
	}

	m := &Machine{
		MachineMeta: meta,
		Log:         log,
		KiteTracker: kitepinger.NewPingTracker(kitePinger),
		HTTPTracker: kitepinger.NewPingTracker(httpPinger),
		Transport:   t,
		discover:    discover.NewClient(),
		mountLocker: util.NewMutexWithState(),
	}

	m.discover.Log = m.Log.New("discover")

	// Start our http pinger, to give online/offline statuses for all machines.
	m.HTTPTracker.Start()

	return m, nil
}
开发者ID:koding,项目名称:koding,代码行数:31,代码来源:machine.go

示例3: NewAddresses

// NewAddresses fetches EC2 IP address list from each region.
//
// If log is nil, defaultLogger is used instead.
func NewAddresses(clients *amazon.Clients, log logging.Logger) *Addresses {
	if log == nil {
		log = defaultLogger
	}
	a := newAddresses()
	var wg sync.WaitGroup
	var mu sync.Mutex // protects a.m
	for region, client := range clients.Regions() {
		wg.Add(1)
		go func(region string, client *amazon.Client) {
			defer wg.Done()
			addresses, err := client.Addresses()
			if err != nil {
				log.Error("[%s] fetching IP addresses error: %s", region, err)
				return
			}
			log.Info("[%s] fetched %d addresses", region, len(addresses))
			var ok bool
			mu.Lock()
			if _, ok = a.m[client]; !ok {
				a.m[client] = addresses
			}
			mu.Unlock()
			if ok {
				panic(fmt.Errorf("[%s] duplicated client=%p: %+v", region, client, addresses))
			}
		}(region, client)
	}
	wg.Wait()
	return a
}
开发者ID:koding,项目名称:koding,代码行数:34,代码来源:addresses.go

示例4: CreateMetrics

func CreateMetrics(appName string, log logging.Logger, outputMetrics bool) (*kodingmetrics.Metrics, *kodingmetrics.DogStatsD) {
	metric := kodingmetrics.New(appName)

	// if outputMetrics, do print output to the console
	if outputMetrics {
		// change those loggers
		// https://github.com/rcrowley/go-metrics/blob/37df06ff62a7d8b4473b48d355008c838da87561/log.go
		// get those numbers from config
		// output metrics every 1 minutes
		go metrics.Log(metric.Registry, 6e10, slog.New(os.Stderr, "metrics: ", slog.Lmicroseconds))
	}

	// Left here for future reference

	// for Mac
	syslogPath := "/var/run/syslog"
	if runtime.GOOS != "darwin" {
		// for linux
		syslogPath = "/dev/log"
	}

	w, err := syslog.Dial("unixgram", syslogPath, syslog.LOG_INFO, "socialapi-metrics")
	if err != nil {
		log.Error("Err while initing syslog for metrics, metrics wont be in the syslog %s", err.Error())
	} else {
		go metrics.Syslog(metric.Registry, 30e10, w)
	}

	statsd, err := kodingmetrics.NewDogStatsD(appName)
	if err == nil {
		go kodingmetrics.Collect(metric.Registry, statsd, 24e10)
	}

	return metric, statsd
}
开发者ID:,项目名称:,代码行数:35,代码来源:

示例5: Join

// Join copies data between local and remote connections.
// It reads from one connection and writes to the other.
// It's a building block for ProxyFunc implementations.
func Join(local, remote net.Conn, log logging.Logger) {
	var wg sync.WaitGroup
	wg.Add(2)

	transfer := func(side string, dst, src net.Conn) {
		log.Debug("proxing %s -> %s", src.RemoteAddr(), dst.RemoteAddr())

		n, err := io.Copy(dst, src)
		if err != nil {
			log.Error("%s: copy error: %s", side, err)
		}

		if err := src.Close(); err != nil {
			log.Debug("%s: close error: %s", side, err)
		}

		// not for yamux streams, but for client to local server connections
		if d, ok := dst.(*net.TCPConn); ok {
			if err := d.CloseWrite(); err != nil {
				log.Debug("%s: closeWrite error: %s", side, err)
			}

		}
		wg.Done()
		log.Debug("done proxing %s -> %s: %d bytes", src.RemoteAddr(), dst.RemoteAddr(), n)
	}

	go transfer("remote to local", local, remote)
	go transfer("local to remote", remote, local)

	wg.Wait()
}
开发者ID:,项目名称:,代码行数:35,代码来源:

示例6: New

func New(log logging.Logger, client algoliasearch.Client, indexSuffix string) *Controller {
	// TODO later on listen channel_participant_added event and remove this koding channel fetch
	c := models.NewChannel()
	q := request.NewQuery()
	q.GroupName = "koding"
	q.Name = "public"
	q.Type = models.Channel_TYPE_GROUP

	channel, err := c.ByName(q)
	if err != nil {
		log.Error("Could not fetch koding channel: %s:", err)
	}
	var channelId string
	if channel.Id != 0 {
		channelId = strconv.FormatInt(channel.Id, 10)
	}

	controller := &Controller{
		log:    log,
		client: client,
		indexes: &IndexSet{
			IndexTopics: &IndexSetItem{
				Index: client.InitIndex(IndexTopics + indexSuffix),
				Settings: &Settings{
					// empty slice means all properties will be searchable
					AttributesToIndex: []string{},
				},
			},
			IndexAccounts: &IndexSetItem{
				Index: client.InitIndex(IndexAccounts + indexSuffix),
				Settings: &Settings{
					AttributesToIndex: []string{
						"nick",
						"email",
						"firstName",
						"lastName",
						"_tags",
					},
					UnretrievableAttributes: []string{"email"},
				},
			},
			IndexMessages: &IndexSetItem{
				Index: client.InitIndex(IndexMessages + indexSuffix),
				Settings: &Settings{
					AttributesToIndex: []string{},
				},
			},
		},
		kodingChannelId: channelId,
	}

	return controller
}
开发者ID:,项目名称:,代码行数:53,代码来源:

示例7: setDefaults

func setDefaults(log logging.Logger) {
	group, err := modelhelper.GetGroup(models.Channel_KODING_NAME)
	if err != nil {
		log.Error("err while fetching koding group: %s", err.Error())
		return
	}

	log.Debug("mongo group found")

	setPublicChannel(log, group)
	setChangeLogChannel(log, group)
	log.Info("socialApi defaults are created")
}
开发者ID:,项目名称:,代码行数:13,代码来源:

示例8: FactoryCompletion

// FactoryCompletion implements codeganstas cli.Command's bash completion field
func FactoryCompletion(factory CommandFactory, log logging.Logger, cmdName string) cli.BashCompleteFunc {
	return func(c *cli.Context) {
		cmd := factory(c, log, cmdName)

		// If the command implements AutocompleteCommand, run the autocomplete.
		if aCmd, ok := cmd.(AutocompleteCommand); ok {
			if err := aCmd.Autocomplete(c.Args()...); err != nil {
				log.Error(
					"Autocompletion of a command encountered error. command:%s, err:%s",
					cmdName, err,
				)
			}
		}
	}
}
开发者ID:,项目名称:,代码行数:16,代码来源:

示例9: ExitErrAction

// ExitErrAction implements a cli.Command's Action field for an ExitingErrCommand
func ExitErrAction(f ExitingErrCommand, log logging.Logger, cmdName string) cli.ActionFunc {
	return func(c *cli.Context) error {
		exit, err := f(c, log, cmdName)
		if err != nil {
			log.Error("ExitErrAction encountered error. err:%s", err)
			// Print error message to the user.
			fmt.Fprintf(os.Stderr, "error executing %q command: %s\n", cmdName, err)
		}

		Close()
		ExitFunc(exit)

		return nil
	}
}
开发者ID:,项目名称:,代码行数:16,代码来源:

示例10: setChangeLogChannel

func setChangeLogChannel(log logging.Logger, group *kodingmodels.Group) {

	c := models.NewChannel()
	selector := map[string]interface{}{
		"type_constant": models.Channel_TYPE_ANNOUNCEMENT,
		"group_name":    models.Channel_KODING_NAME,
	}

	// if err is nil
	// it means we already have that channel
	err := c.One(bongo.NewQS(selector))
	if err != nil && err != bongo.RecordNotFound {
		log.Error("err while fetching changelog channel:", err.Error())
		return
	}

	if err == bongo.RecordNotFound {
		log.Error("postgres changelog couldn't found, creating it")

		acc, err := createChannelOwner(group)
		if err != nil {
			log.Error(err.Error())
			return
		}

		c.Name = "changelog"
		c.CreatorId = acc.Id
		c.GroupName = models.Channel_KODING_NAME
		c.TypeConstant = models.Channel_TYPE_ANNOUNCEMENT
		c.PrivacyConstant = models.Channel_PRIVACY_PRIVATE
		if err := c.Create(); err != nil {
			log.Error("err while creating the koding channel:", err.Error())
			return
		}
	}

	socialApiAnnouncementChannelId := strconv.FormatInt(c.Id, 10)
	if group.SocialApiAnnouncementChannelId == socialApiAnnouncementChannelId {
		log.Info("mongo and postgres socialApiAnnouncementChannel ids are same")
		return
	}

	log.Debug("mongo and postgres socialApiAnnouncementChannel ids are different, fixing it")
	if err := updateGroupPartially(group.Id, "socialApiAnnouncementChannelId", strconv.FormatInt(c.Id, 10)); err != nil {
		log.Error("err while udpating socialApiAnnouncementChannelId:", err.Error())
		return
	}
}
开发者ID:,项目名称:,代码行数:48,代码来源:

示例11: RestartCommand

// RestartCommand stops and starts klient. If Klient is not running to begin
// with, it *just* starts klient.
func RestartCommand(c *cli.Context, log logging.Logger, _ string) int {
	if len(c.Args()) != 0 {
		cli.ShowCommandHelp(c, "restart")
		return 1
	}

	log = log.New("cmd:restart")

	s, err := newService(nil)
	if err != nil {
		log.Error("Error creating Service. err:%s", err)
		fmt.Println(GenericInternalNewCodeError)
		return 1
	}

	fmt.Printf("Restarting the %s, this may take a moment...\n", config.KlientName)

	klientWasRunning := IsKlientRunning(config.Konfig.Endpoints.Klient.Private.String())

	if klientWasRunning {
		// If klient is running, stop it, and tell the user if we fail
		if err := s.Stop(); err != nil {
			log.Error("Error stopping Service. err:%s", err)
			fmt.Println(FailedStopKlient)
			return 1
		}
	} else {
		// If klient appears to not be running, try to stop it anyway. However,
		// because it may not actually be running, don't inform the user if we fail here.
		s.Stop()
	}

	err = WaitUntilStopped(config.Konfig.Endpoints.Klient.Private.String(), CommandAttempts, CommandWaitTime)
	if err != nil {
		log.Error(
			"Timed out while waiting for Klient to start. attempts:%d, err:%s",
			5, err,
		)
		fmt.Println(FailedStopKlient)
		return 1
	}

	if klientWasRunning {
		fmt.Println("Stopped successfully.")
	}

	// No UX message needed, startKlient will do that itself.
	if err := startKlient(log, s); err != nil {
		log.Error("failed to start klient: %s", err)
		return 1
	}

	fmt.Printf("Successfully restarted %s\n", config.KlientName)
	return 0
}
开发者ID:,项目名称:,代码行数:57,代码来源:

示例12: startIntervalerIfNeeded

// startIntervalerIfNeeded starts the given rsync interval, logs any errors, and adds the
// resulting Intervaler to the Mount struct for later Stoppage.
func startIntervalerIfNeeded(log logging.Logger, remoteMachine *machine.Machine, c *rsync.Client, opts rsync.SyncIntervalOpts) {
	log = log.New("startIntervalerIfNeeded")

	if opts.Interval <= 0 {
		// Using debug, because this is not an error - just informative.
		log.Debug(
			"startIntervalerIfNeeded() called with interval:%d. Cannot start Intervaler",
			opts.Interval,
		)
		return
	}

	log.Info("Creating and starting RSync SyncInterval")
	intervaler, err := c.SyncInterval(opts)
	if err != nil {
		log.Error("rsync SyncInterval returned an error:%s", err)
		return
	}

	remoteMachine.Intervaler = intervaler
}
开发者ID:koding,项目名称:koding,代码行数:23,代码来源:cache.go

示例13: StopCommand

// StopCommand stop local klient. Requires sudo.
func StopCommand(c *cli.Context, log logging.Logger, _ string) int {
	if len(c.Args()) != 0 {
		cli.ShowCommandHelp(c, "stop")
		return 1
	}

	s, err := newService(nil)
	if err != nil {
		log.Error("Error creating Service. err:%s", err)
		fmt.Println(GenericInternalError)
		return 1
	}

	if err := s.Stop(); err != nil {
		log.Error("Error stopping Service. err:%s", err)
		fmt.Println(FailedStopKlient)
		return 1
	}

	err = WaitUntilStopped(config.Konfig.Endpoints.Klient.Private.String(), CommandAttempts, CommandWaitTime)
	if err != nil {
		log.Error(
			"Timed out while waiting for Klient to start. attempts:%d, err:%s",
			5, err,
		)
		fmt.Println(FailedStopKlient)
		return 1
	}

	fmt.Printf("Successfully stopped %s\n", config.KlientName)
	return 0
}
开发者ID:,项目名称:,代码行数:33,代码来源:

示例14: FactoryAction

// FactoryAction implements a cli.Command's Action field.
func FactoryAction(factory CommandFactory, log logging.Logger, cmdName string) cli.ActionFunc {
	return func(c *cli.Context) error {
		cmd := factory(c, log, cmdName)
		exit, err := cmd.Run()

		// For API reasons, we may return an error but a zero exit code. So we want
		// to check and log both.
		if exit != 0 || err != nil {
			log.Error(
				"Command encountered error. command:%s, exit:%d, err:%s",
				cmdName, exit, err,
			)
			// Print error message to the user.
			fmt.Fprintf(os.Stderr, "error executing %q command: %s\n", cmdName, err)
		}

		Close()
		ExitFunc(exit)

		return nil
	}
}
开发者ID:,项目名称:,代码行数:23,代码来源:

示例15: startKlient

func startKlient(log logging.Logger, s service.Service) error {
	// For debug purposes, run a health check before we even attempt to start. This
	// will help give us a sense of what this machine's health check was before
	// klient tried to start.
	if res, ok := defaultHealthChecker.CheckAllExceptRunning(); !ok {
		log.Warning("before attempting to start klient health check returned not-okay. reason: %s", res)
	}

	if err := s.Start(); err != nil {
		log.Error("Error starting Service. err:%s", err)
		fmt.Println(FailedStartKlient)
		return err
	}

	fmt.Println("Starting...")

	err := WaitUntilStarted(config.Konfig.Endpoints.Klient.Private.String(), CommandAttempts, CommandWaitTime)
	if err != nil {
		log.Error(
			"Timed out while waiting for Klient to start. attempts:%d, err:%s",
			CommandAttempts, err,
		)

		if s, ok := defaultHealthChecker.CheckAllExceptRunning(); !ok {
			fmt.Printf(`Failed to start %s in time.

A health check found the following issue:
%s
`, config.KlientName, s)
		} else {
			fmt.Println(FailedStartKlient)
		}

		return err
	}

	return nil
}
开发者ID:,项目名称:,代码行数:38,代码来源:


注:本文中的github.com/koding/logging.Logger.Error方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。