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


Golang log.Error函數代碼示例

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


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

示例1: FetchURL

// FetchURL fetches url and saves as a file, it includes retry and decoding bson.
func (p *BsonProxy) FetchURL(ref string) (string, error) {
	for tryCount := 0; tryCount < maxRetry; tryCount++ {
		if tryCount > 0 {
			log.Warnf("Retry after %d times", tryCount)
			time.Sleep(retryInterval)
		}
		resp, err := p.c.Get(ref)
		if err != nil {
			log.Error(err)
			continue
		}
		f, err := ioutil.TempFile(os.TempDir(), "duokan")
		if err != nil {
			log.Error(err)
			continue
		}
		// Why use ioutil.ReadAll doesn't work? It seems resp.Body can't Close,
		// so reader is blocking.
		_, err = io.Copy(f, resp.Body)
		if err != nil {
			log.Errorf("Get error url[%s], err[%s]", ref, err)
			continue
		}
		err = f.Close()
		if err != nil {
			log.Error(err)
			continue
		}
		return f.Name(), nil
	}
	return "", errors.Errorf("reach max retry time [%d]", maxRetry)
}
開發者ID:morefreeze,項目名稱:dkbson,代碼行數:33,代碼來源:book_info.go

示例2: GrabJDHTML

//抓取京東商品頁麵
func GrabJDHTML(url string) string {
	req, err := http.NewRequest("GET", url, nil)
	if err != nil {
		log.Error(err)
		return ""
	}

	req.Header.Set("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8")
	req.Header.Set("Accept-Language", "zh-CN,zh;q=0.8")
	req.Header.Set("Cache-Control", "no-cache")
	req.Header.Set("Connection", "keep-alive")
	req.Header.Set("Pragma", "no-cache")

	if req.UserAgent() == "" {
		l := len(agent.UserAgents["common"])
		r := rand.New(rand.NewSource(time.Now().UnixNano()))
		req.Header.Set("User-Agent", agent.UserAgents["common"][r.Intn(l)])
	}
	//	client.Lock()
	//	defer client.Unlock()
	resp, err := client.Do(req)
	if err != nil {
		log.Error(err)
		return ""
	}

	if resp.Body != nil {
		defer resp.Body.Close()
		return changeCharsetEncodingAuto(resp.Body, resp.Header.Get("Content-Type"))
	}
	return ""
}
開發者ID:qgweb,項目名稱:new,代碼行數:33,代碼來源:jd.go

示例3: uniq

func (this *DispathWriter) uniq(fn string) {
	generator := exec.Command("sort", fn)
	consumer := exec.Command("uniq")

	p, err := generator.StdoutPipe()
	if err != nil {
		log.Error(err)
		return
	}
	generator.Start()
	consumer.Stdin = p
	pp, err := consumer.StdoutPipe()
	if err != nil {
		log.Error(err)
		return
	}
	consumer.Start()
	f, err := os.Create(fn + ".bak")
	if err != nil {
		log.Error(err)
		return
	}
	io.Copy(f, pp)
	f.Close()
	os.Rename(fn+".bak", fn)
}
開發者ID:qgweb,項目名稱:new,代碼行數:26,代碼來源:storage.go

示例4: run

func (this *Domain) run() {
	defer func() {
		if err := recover(); err != nil {
			log.Error(err)
			debug.PrintStack()
		}
	}()

	this.kvf.AddFun(this.domainData)
	log.Error(this.kvf.WriteFile())
	this.cleanPutTable()
	log.Error(this.kvf.Origin(this.saveData))
	this.mgb.Flush()
}
開發者ID:qgweb,項目名稱:new,代碼行數:14,代碼來源:url.go

示例5: run

func (this *UserTrack) run() {
	defer func() {
		if err := recover(); err != nil {
			log.Error(err)
			debug.PrintStack()
		}
	}()
	this.kvf.AddFun(this.businessData)
	this.kvf.AddFun(this.otherData)
	log.Error(this.kvf.WriteFile())
	this.cleanPutTable()
	log.Error(this.kvf.Origin(this.saveData))
	this.mgb.Flush()
	this.mgb_big.Flush()
}
開發者ID:qgweb,項目名稱:new,代碼行數:15,代碼來源:other.go

示例6: CurrentVersion

// CurrentVersion implements the VersionProvider's GetCurrentVer interface.
func (l *LocalVersionProvider) CurrentVersion() (kv.Version, error) {
	l.mu.Lock()
	defer l.mu.Unlock()

	for {
		var ts uint64
		ts = uint64((time.Now().UnixNano() / int64(time.Millisecond)) << timePrecisionOffset)

		if l.lastTimestamp > ts {
			log.Error("invalid physical time stamp")
			continue
		}

		if l.lastTimestamp == uint64(ts) {
			l.logical++
			if l.logical >= 1<<timePrecisionOffset {
				return kv.Version{}, ErrOverflow
			}
			return kv.Version{Ver: ts + l.logical}, nil
		}
		l.lastTimestamp = ts
		l.logical = 0
		return kv.Version{Ver: ts}, nil
	}
}
開發者ID:henrylee2cn,項目名稱:tidb,代碼行數:26,代碼來源:local_version_provider.go

示例7: startStatusHTTP

func (s *Server) startStatusHTTP() {
	once.Do(func() {
		go func() {
			http.HandleFunc("/status", func(w http.ResponseWriter, req *http.Request) {
				w.Header().Set("Content-Type", "application/json")
				s := status{
					Connections: s.ConnectionCount(),
					Version:     mysql.ServerVersion,
					GitHash:     printer.TiDBGitHash,
				}
				js, err := json.Marshal(s)
				if err != nil {
					w.WriteHeader(http.StatusInternalServerError)
					log.Error("Encode json error", err)
				} else {
					w.Write(js)
				}

			})
			// HTTP path for prometheus.
			http.Handle("/metrics", prometheus.Handler())
			addr := s.cfg.StatusAddr
			if len(addr) == 0 {
				addr = defaultStatusAddr
			}
			log.Infof("Listening on %v for status and metrics report.", addr)
			err := http.ListenAndServe(addr, nil)
			if err != nil {
				log.Fatal(err)
			}
		}()
	})
}
開發者ID:pingcap,項目名稱:tidb,代碼行數:33,代碼來源:server.go

示例8: TestOrderBy

func (t *testOrderBySuit) TestOrderBy(c *C) {
	tblPlan := &testTablePlan{t.data, []string{"id", "name"}}

	pln := &OrderByDefaultPlan{
		SelectList: &SelectList{
			HiddenFieldOffset: len(tblPlan.GetFields()),
			ResultFields:      tblPlan.GetFields(),
		},
		Src: tblPlan,
		By: []expression.Expression{
			&expressions.Ident{
				CIStr: model.NewCIStr("id"),
			},
		},
		Ascs: []bool{false},
	}

	prev := 10000
	err := pln.Do(nil, func(id interface{}, data []interface{}) (bool, error) {
		// DESC
		if data[0].(int) > prev {
			c.Error("should no be here", data[0], prev)
		}
		prev = data[0].(int)
		return true, nil
	})
	if err != nil {
		log.Error(err)
	}
}
開發者ID:ninefive,項目名稱:tidb,代碼行數:30,代碼來源:orderby_test.go

示例9: GetFeedById

func GetFeedById(channelName string, id int) *Feed {
	var ret *Feed
	err := db.Update(func(tx *bolt.Tx) error {
		bucketName := append(channelBucketNamePrefix, []byte(channelName)...)
		b, err := tx.CreateBucketIfNotExists(bucketName)
		if err != nil {
			return err
		}
		key := fmt.Sprintf("item:id:%d", id)
		bb := b.Get([]byte(key))
		if bb != nil {
			var t Feed
			err := json.Unmarshal(bb, &t)
			if err != nil {
				return err
			}
			ret = &t
		}
		return nil
	})
	if err != nil {
		log.Error(err)
	}
	return ret
}
開發者ID:wrabbit-revisited,項目名稱:rss_server,代碼行數:25,代碼來源:feeds.go

示例10: saveTraceToDianxin

// 保存投放軌跡到電信ftp
func (this *JsPut) saveTraceToDianxin() {
	var (
		ftp     = lib.GetConfVal("jiangsu::ftp_path")
		ppath   = lib.GetConfVal("jiangsu::put_path")
		rk      = "account.10046.sha1." + time.Now().Add(-time.Hour).Format("200601021504")
		fname   = ppath + "/" + rk
		adcount = 0
	)

	f, err := os.Create(fname)
	if err != nil {
		log.Error("創建文件失敗", err)
		return
	}
	defer f.Close()

	this.kf.AdSet(func(ad string) {
		if v, ok := this.areamap[ad]; ok {
			f.WriteString(ad + "," + v + "\n")
			adcount++
		}
	})
	cmd := exec.Command(ftp, rk)
	str, err := cmd.Output()
	log.Info(string(str), err)

	// 廣告數量統計數據 dx_stats , js_1461016800, 11111
	lib.StatisticsData("dx_stats", fmt.Sprintf("js_%s", timestamp.GetHourTimestamp(-1)),
		convert.ToString(adcount), "")
}
開發者ID:qgweb,項目名稱:new,代碼行數:31,代碼來源:js.go

示例11: unflatten

func (t *Table) unflatten(rec interface{}, col *column.Col) (interface{}, error) {
	if rec == nil {
		return nil, nil
	}
	switch col.Tp {
	case mysql.TypeFloat:
		return float32(rec.(float64)), nil
	case mysql.TypeTiny, mysql.TypeShort, mysql.TypeYear, mysql.TypeInt24, mysql.TypeLong, mysql.TypeLonglong,
		mysql.TypeDouble, mysql.TypeTinyBlob, mysql.TypeMediumBlob, mysql.TypeBlob, mysql.TypeLongBlob,
		mysql.TypeVarchar, mysql.TypeString:
		return rec, nil
	case mysql.TypeDate, mysql.TypeDatetime, mysql.TypeTimestamp:
		var t mysql.Time
		t.Type = col.Tp
		t.Fsp = col.Decimal
		err := t.Unmarshal(rec.([]byte))
		if err != nil {
			return nil, errors.Trace(err)
		}
		return t, nil
	case mysql.TypeDuration:
		return mysql.Duration{Duration: time.Duration(rec.(int64)), Fsp: col.Decimal}, nil
	case mysql.TypeNewDecimal, mysql.TypeDecimal:
		return mysql.ParseDecimal(rec.(string))
	case mysql.TypeEnum:
		return mysql.ParseEnumValue(col.Elems, rec.(uint64))
	case mysql.TypeSet:
		return mysql.ParseSetValue(col.Elems, rec.(uint64))
	case mysql.TypeBit:
		return mysql.Bit{Value: rec.(uint64), Width: col.Flen}, nil
	}
	log.Error(col.Tp, rec, reflect.TypeOf(rec))
	return nil, nil
}
開發者ID:remotesyssupport,項目名稱:tidb,代碼行數:34,代碼來源:tables.go

示例12: GetSchemaVersion

// GetSchemaVersion gets schema version in the context.
func GetSchemaVersion(ctx context.Context) int64 {
	v, ok := ctx.Value(schemaVersionKey).(int64)
	if !ok {
		log.Error("get schema version failed")
	}
	return v
}
開發者ID:jmptrader,項目名稱:tidb,代碼行數:8,代碼來源:binloginfo.go

示例13: doKeepAlive

func (e *etcdImpl) doKeepAlive(key string, ttl uint64) error {
	conn, err := e.pool.Get()
	if err != nil {
		return err
	}

	defer e.pool.Put(conn)
	c := conn.(*PooledEtcdClient).c

	resp, err := c.Get(key, false, false)
	if err != nil {
		log.Error(err)
		return err
	}

	if resp.Node.Dir {
		return fmt.Errorf("can not set ttl to directory", key)
	}

	//log.Info("keep alive ", key)
	resp, err = c.CompareAndSwap(key, resp.Node.Value, ttl, resp.Node.Value, resp.Node.ModifiedIndex)
	if err == nil {
		return nil
	}

	if ec, ok := err.(*etcd.EtcdError); ok && ec.ErrorCode == etcderr.EcodeTestFailed {
		return nil
	}

	return err
}
開發者ID:Goyoo,項目名稱:codis-docker,代碼行數:31,代碼來源:etcd.go

示例14: saveTraceToPutSys

// 保存投放軌跡到投放係統
func (this *ZjPut) saveTraceToPutSys() {
	rdb, err := lib.GetPutRedisObj("put_redis_proxy_url")
	if err != nil {
		log.Error("redis連接失敗", err)
		return
	}
	go func() {
		for {
			rdb.Receive()
		}
	}()
	//rdb.SelectDb("1")
	adcount := 0
	this.kf.AdUaIdsSet(func(ad string, ua string, aids map[string]int8) {
		key := ad
		if ua != "ua" {
			key = encrypt.DefaultMd5.Encode(ad + "_" + ua)
		}
		for aid, _ := range aids {
			rdb.HSet(key, "advert:"+aid, aid)
		}
		rdb.Expire(key, 5400)
		adcount++
	})
	rdb.Flush()
	rdb.Close()
	// 廣告數量統計數據 put_stats , Zj_1461016800, 11111
	lib.StatisticsData("put_stats", fmt.Sprintf("zj_%s", this.Timestamp),
		convert.ToString(adcount), "")
}
開發者ID:qgweb,項目名稱:new,代碼行數:31,代碼來源:zj.go

示例15: cmdDashboard

func cmdDashboard(argv []string) (err error) {
	usage := `usage: reborn-config dashboard [--addr=<address>] [--http-log=<log_file>]

options:
	--addr		listen ip:port, e.g. localhost:12345, :8086, [default: :8086]
	--http-log	http request log [default: request.log ]
`

	args, err := docopt.Parse(usage, argv, true, "", false)
	if err != nil {
		log.Error(err)
		return errors.Trace(err)
	}
	log.Debug(args)

	logFileName := "request.log"
	if args["--http-log"] != nil {
		logFileName = args["--http-log"].(string)
	}

	addr := ":8086"
	if args["--addr"] != nil {
		addr = args["--addr"].(string)
	}

	runDashboard(addr, logFileName)
	return nil
}
開發者ID:vebin,項目名稱:reborn,代碼行數:28,代碼來源:dashboard.go


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