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


Golang logging.Errorf函數代碼示例

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


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

示例1: BeforePromote

func BeforePromote(oldMaster string) error {
	conn, _ := zkhelper.ConnectToZk(*zkAddr)
	defer conn.Close()

	groups, err := models.ServerGroups(conn, *productName)
	if err != nil {
		log.Errorf("get server groups error %v, give up failover", err)
		return failover.ErrGiveupFailover
	}

	found := false
	for _, group := range groups {
		for _, server := range group.Servers {
			if server.Addr == oldMaster {
				found = true
				break
			}
		}
	}

	if !found {
		log.Errorf("can not find %s in any groups, give up failover", oldMaster)
		return failover.ErrGiveupFailover
	}

	return nil
}
開發者ID:jameswei,項目名稱:xcodis,代碼行數:27,代碼來源:failover.go

示例2: Run

func (c *Conn) Run() {
	defer func() {
		r := recover()
		if err, ok := r.(error); ok {
			const size = 4096
			buf := make([]byte, size)
			buf = buf[:runtime.Stack(buf, false)]

			log.Errorf("lastCmd %s, %v, %s", c.lastCmd, err, buf)
		}

		c.Close()
	}()

	for {
		c.alloc.Reset()
		data, err := c.readPacket()
		if err != nil {
			if err.Error() != io.EOF.Error() {
				log.Info(err)
			}
			return
		}

		if err := c.dispatch(data); err != nil {
			log.Errorf("dispatch error %s, %s", errors.ErrorStack(err), c)
			if err != mysql.ErrBadConn { //todo: fix this
				c.writeError(err)
			}
		}

		c.pkg.Sequence = 0
	}
}
開發者ID:sdgdsffdsfff,項目名稱:cm,代碼行數:34,代碼來源:conn.go

示例3: handleCrashedServer

func handleCrashedServer(s *models.Server) error {
	switch s.Type {
	case models.SERVER_TYPE_MASTER:
		//get slave and do promote
		slave, err := getSlave(s)
		if err != nil {
			log.Warning(errors.ErrorStack(err))
			return err
		}

		log.Infof("try promote %+v", slave)
		err = callHttp(nil, genUrl(*apiServer, "/api/server_group/", slave.GroupId, "/promote"), "POST", slave)
		if err != nil {
			log.Errorf("do promote %v failed %v", slave, errors.ErrorStack(err))
			return err
		}
		refreshSlave(s) //刷新
	case models.SERVER_TYPE_SLAVE:
		log.Errorf("slave is down: %+v", s)
	case models.SERVER_TYPE_OFFLINE:
		//no need to handle it
	default:
		log.Fatalf("unkonwn type %+v", s)
	}

	return nil
}
開發者ID:sfcuboy,項目名稱:codis-ha,代碼行數:27,代碼來源:servergroup.go

示例4: slotsReloadLoop

// wait for the slot reload chan and reload cluster topology
// at most every slotReloadInterval
// it also reload topology at a relative long periodic interval
func (d *Dispatcher) slotsReloadLoop() {
	periodicReloadInterval := 60 * time.Second
	for {
		select {
		case <-time.After(d.slotReloadInterval):
			select {
			case _, ok := <-d.slotReloadChan:
				if !ok {
					log.Infof("exit reload slot table loop")
					return
				}
				log.Infof("request reload triggered")
				if slotInfos, err := d.reloadTopology(); err != nil {
					log.Errorf("reload slot table failed")
				} else {
					d.slotInfoChan <- slotInfos
				}
			case <-time.After(periodicReloadInterval):
				log.Infof("periodic reload triggered")
				if slotInfos, err := d.reloadTopology(); err != nil {
					log.Errorf("reload slot table failed")
				} else {
					d.slotInfoChan <- slotInfos
				}
			}
		}
	}
}
開發者ID:bytedance,項目名稱:rcproxy,代碼行數:31,代碼來源:dispatcher.go

示例5: publishMainStats

func (s *MemcacheStats) publishMainStats() {
	s.mu.Lock()
	defer s.mu.Unlock()
	s.main = make(map[string]string)
	for key, isstr := range mainStringMetrics {
		key := key
		if isstr {
			s.main[key] = ""
			stats.Publish(s.cachePool.name+"Memcache"+formatKey(key), stats.StringFunc(func() string {
				s.mu.Lock()
				defer s.mu.Unlock()
				return s.main[key]
			}))
		} else {
			s.main[key] = "0"
			stats.Publish(s.cachePool.name+"Memcache"+formatKey(key), stats.IntFunc(func() int64 {
				s.mu.Lock()
				defer s.mu.Unlock()
				ival, err := strconv.ParseInt(s.main[key], 10, 64)
				if err != nil {
					log.Errorf("value '%v' for key %v is not an int", s.main[key], key)
					internalErrors.Add("MemcacheStats", 1)
					return -1
				}
				return ival
			}))
		}
	}
}
開發者ID:sdgdsffdsfff,項目名稱:cm,代碼行數:29,代碼來源:memcache_stats.go

示例6: WaitForReceiverWithTimeout

func WaitForReceiverWithTimeout(zkConn zkhelper.Conn, productName string, actionZkPath string, proxies []ProxyInfo, timeoutInMs int) error {
	if len(proxies) == 0 {
		return nil
	}

	times := 0
	proxyIds := make(map[string]struct{})
	var offlineProxyIds []string
	for _, p := range proxies {
		proxyIds[p.Id] = struct{}{}
	}

	checkTimes := timeoutInMs / 500
	// check every 500ms
	for times < checkTimes {
		if times >= 6 && (times*500)%1000 == 0 {
			log.Warning("abnormal waiting time for receivers", actionZkPath, offlineProxyIds)
		}
		// get confirm ids
		nodes, _, err := zkConn.Children(actionZkPath)
		if err != nil {
			return errors.Trace(err)
		}
		confirmIds := make(map[string]struct{})
		for _, node := range nodes {
			id := path.Base(node)
			confirmIds[id] = struct{}{}
		}
		if len(confirmIds) != 0 {
			match := true
			// check if all proxy have responsed
			var notMatchList []string
			for id, _ := range proxyIds {
				// if proxy id not in confirm ids, means someone didn't response
				if _, ok := confirmIds[id]; !ok {
					match = false
					notMatchList = append(notMatchList, id)
				}
			}
			if match {
				return nil
			}
			offlineProxyIds = notMatchList
		}
		times += 1
		time.Sleep(500 * time.Millisecond)
	}
	if len(offlineProxyIds) > 0 {
		log.Error("proxies didn't responed: ", offlineProxyIds)
	}

	// set offline proxies
	for _, id := range offlineProxyIds {
		log.Errorf("mark proxy %s to PROXY_STATE_MARK_OFFLINE", id)
		if err := SetProxyStatus(zkConn, productName, id, PROXY_STATE_MARK_OFFLINE); err != nil {
			return errors.Trace(err)
		}
	}
	return errors.Trace(ErrReceiverTimeout)
}
開發者ID:ZuoGuocai,項目名稱:codis,代碼行數:60,代碼來源:action.go

示例7: handleMesosError

func (self *ResMan) handleMesosError(t *cmdMesosError) {
	defer func() {
		t.wait <- struct{}{}
	}()

	log.Errorf("%s\n", t.err)
}
開發者ID:NextMark,項目名稱:tyrant,代碼行數:7,代碼來源:scheduler.go

示例8: Raw

func Raw(t byte, val Value, isUnsigned bool) []byte {
	if val == nil {
		return nil
	}

	var ret []byte
	switch t {
	case MYSQL_TYPE_TINY, MYSQL_TYPE_SHORT, MYSQL_TYPE_INT24, MYSQL_TYPE_LONG,
		MYSQL_TYPE_LONGLONG, MYSQL_TYPE_YEAR:
		if isUnsigned {
			ret = []byte(strconv.FormatUint(val.(uint64), 10))
		} else {
			ret = []byte(strconv.FormatInt(val.(int64), 10))
		}

	case MYSQL_TYPE_FLOAT, MYSQL_TYPE_DOUBLE:
		ret = []byte(strconv.FormatFloat(val.(float64), 'f', 16, 64))
	case MYSQL_TYPE_VARCHAR:
		str, ok := val.(string)
		if ok {
			ret = hack.Slice(str)
			break
		}

		fallthrough
	default:
		var ok bool
		ret, ok = val.([]byte)
		if !ok {
			log.Errorf("%v, %+v, %T", t, val, val)
		}
	}

	return ret
}
開發者ID:sdgdsffdsfff,項目名稱:cm,代碼行數:35,代碼來源:resultset.go

示例9: updateItemsStats

func (s *MemcacheStats) updateItemsStats() {
	if s.items == nil {
		return
	}
	s.readStats("items", func(sKey, sValue string) {
		ival, err := strconv.ParseInt(sValue, 10, 64)
		if err != nil {
			log.Error(err)
			internalErrors.Add("MemcacheStats", 1)
			return
		}
		subkey, slabid, err := parseItemKey(sKey)
		if err != nil {
			log.Error(err)
			internalErrors.Add("MemcacheStats", 1)
			return
		}
		m, ok := s.items[subkey]
		if !ok {
			log.Errorf("Unknown memcache items stats %v %v: %v", subkey, slabid, ival)
			internalErrors.Add("MemcacheStats", 1)
			return
		}
		m[slabid] = ival
	})
}
開發者ID:sdgdsffdsfff,項目名稱:cm,代碼行數:26,代碼來源:memcache_stats.go

示例10: refreshSlave

func refreshSlave(master *models.Server) {
	var group models.ServerGroup
	err := callHttp(&group, genUrl(*apiServer, "/api/server_group/", master.GroupId), "GET", nil)
	if err == nil {
		for _, s := range group.Servers {
			if s.Type == models.SERVER_TYPE_SLAVE {
				err := callHttp(nil, genUrl(*apiServer, "/api/server_group/", master.GroupId, "/addServer"), "PUT", s)
				if err != nil {
					log.Errorf("slave  refresh failed:  %v error:v%", s, errors.ErrorStack(err))
				}
			}
		}
	} else {
		log.Errorf("slave  refresh failed:  %v", errors.Trace(err))
	}
}
開發者ID:sfcuboy,項目名稱:codis-ha,代碼行數:16,代碼來源:servergroup.go

示例11: OnSlotRangeChange

func (s *Server) OnSlotRangeChange(param *models.SlotMultiSetParam) {
	log.Warningf("slotRangeChange %+v", param)
	if !validSlot(param.From) || !validSlot(param.To) {
		log.Errorf("invalid slot number, %+v", param)
		return
	}

	for i := param.From; i <= param.To; i++ {
		switch param.Status {
		case models.SLOT_STATUS_OFFLINE:
			s.clearSlot(i)
		case models.SLOT_STATUS_ONLINE:
			s.fillSlot(i, true)
		default:
			log.Errorf("can not handle status %v", param.Status)
		}
	}
}
開發者ID:ZuoGuocai,項目名稱:codis,代碼行數:18,代碼來源:router.go

示例12: Run

func (s *Server) Run() error {
	for {
		conn, err := s.listener.Accept()
		if err != nil {
			log.Errorf("accept error %s", err.Error())
			return err
		}

		go s.onConn(conn)
	}

	return nil
}
開發者ID:sdgdsffdsfff,項目名稱:cm,代碼行數:13,代碼來源:server.go

示例13: readStats

func (s *MemcacheStats) readStats(k string, proc func(key, value string)) {
	defer func() {
		if x := recover(); x != nil {
			log.Errorf("Could not read memcache stats: %v", x)
			internalErrors.Add("MemcacheStats", 1)
		}
	}()
	conn := s.cachePool.Get(0)
	// This is not the same as defer rc.cachePool.Put(conn)
	defer func() { s.cachePool.Put(conn) }()

	stats, err := conn.Stats(k)
	if err != nil {
		conn.Close()
		conn = nil
		log.Errorf("Cannot export memcache %v stats: %v", k, err)
		internalErrors.Add("MemcacheStats", 1)
		return
	}

	s.mu.Lock()
	defer s.mu.Unlock()
	st := string(stats)
	lines := strings.Split(st, "\n")
	for _, line := range lines {
		if line == "" {
			continue
		}
		items := strings.Split(line, " ")
		if len(items) < 3 { //liuqi: if using apt-get, memcached info would be:  STAT version 1.4.14 (Ubuntu)
			log.Errorf("Unexpected stats: %v", line)
			internalErrors.Add("MemcacheStats", 1)
			continue
		}
		proc(items[1], items[2])
	}
}
開發者ID:sdgdsffdsfff,項目名稱:cm,代碼行數:37,代碼來源:memcache_stats.go

示例14: WaitForReceiver

func WaitForReceiver(zkConn zkhelper.Conn, productName string, actionZkPath string, proxies []ProxyInfo) error {
	if len(proxies) == 0 {
		return nil
	}

	times := 0
	var proxyIds []string
	var offlineProxyIds []string
	for _, p := range proxies {
		proxyIds = append(proxyIds, p.Id)
	}
	sort.Strings(proxyIds)
	// check every 500ms
	for times < 60 {
		if times >= 6 && (times*500)%1000 == 0 {
			log.Warning("abnormal waiting time for receivers", actionZkPath)
		}
		nodes, _, err := zkConn.Children(actionZkPath)
		if err != nil {
			return errors.Trace(err)
		}
		var confirmIds []string
		for _, node := range nodes {
			id := path.Base(node)
			confirmIds = append(confirmIds, id)
		}
		if len(confirmIds) != 0 {
			sort.Strings(confirmIds)
			if utils.Strings(proxyIds).Eq(confirmIds) {
				return nil
			}
			offlineProxyIds = proxyIds[len(confirmIds)-1:]
		}
		times += 1
		time.Sleep(500 * time.Millisecond)
	}
	if len(offlineProxyIds) > 0 {
		log.Error("proxies didn't responed: ", offlineProxyIds)
	}
	// set offline proxies
	for _, id := range offlineProxyIds {
		log.Errorf("mark proxy %s to PROXY_STATE_MARK_OFFLINE", id)
		if err := SetProxyStatus(zkConn, productName, id, PROXY_STATE_MARK_OFFLINE); err != nil {
			return err
		}
	}

	return ErrReceiverTimeout
}
開發者ID:banyue,項目名稱:codis,代碼行數:49,代碼來源:action.go

示例15: updateSlabsStats

func (s *MemcacheStats) updateSlabsStats() {
	if s.slabs == nil {
		return
	}
	s.readStats("slabs", func(sKey, sValue string) {
		ival, err := strconv.ParseInt(sValue, 10, 64)
		if err != nil {
			log.Error(err)
			internalErrors.Add("MemcacheStats", 1)
			return
		}
		if slabsSingleMetrics[sKey] {
			m, ok := s.slabs[sKey]
			if !ok {
				log.Errorf("Unknown memcache slabs stats %v: %v", sKey, ival)
				internalErrors.Add("MemcacheStats", 1)
				return
			}
			m[""] = ival
			return
		}
		subkey, slabid, err := parseSlabKey(sKey)
		if err != nil {
			log.Error(err)
			internalErrors.Add("MemcacheStats", 1)
			return
		}
		m, ok := s.slabs[subkey]
		if !ok {
			log.Errorf("Unknown memcache slabs stats %v %v: %v", subkey, slabid, ival)
			internalErrors.Add("MemcacheStats", 1)
			return
		}
		m[slabid] = ival
	})
}
開發者ID:sdgdsffdsfff,項目名稱:cm,代碼行數:36,代碼來源:memcache_stats.go


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