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


Golang Logger.Debugf函數代碼示例

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


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

示例1: trade

func (w *Huobi) trade(emaShort, emaLong []float64, EMAMinThreshold float64,
	TresholdLevel int, length int, tradeOnlyAfterSwitch int, tradeAmount string) {
	currentTrend := getTrendAtIndex(emaShort, emaLong, EMAMinThreshold, TresholdLevel, length-1)
	logger.Debugln("currentTrend is ", currentTrend)

	if currentTrend > 1 {
		// Trend is up
		if currentTrend == 3 {
			// Trend is up, also according to the "Buy after X samples"-setting
			if (tradeOnlyAfterSwitch == 1) && (w.latestSolidTrend == 3) {
				// tradeOnlyAfterSwitch==true but the trend has not switched: Don't trade
				logger.Debugln("Trend has not switched (still up). The setting \"tradeOnlyAfterSwitch==true\", so do not trade...")
				return
			}
			w.latestSolidTrend = 3

			if Option["disable_trading"] == "1" {
				logger.Debugln("Simulted BUY (Simulation only: no trade was made)")
			} else {
				logger.Infoln("Trend has switched, 探測到買入點")
				go service.TriggerTrender("探測到買入點")

				w.Do_buy(w.getTradePrice("buy"), tradeAmount)
			}
			//logger.Infoln("Trend is up, but no " + currency + " to spend...");
		} else {
			logger.Debugf("Trend is up, but not for long enough (needs to be \"up\" for at least %d samples)\n", TresholdLevel)
		}
	} else if currentTrend < -1 {
		// Trend is down
		if currentTrend == -3 {
			// Trend is down, also according to the "Sell after X samples"-setting
			if (tradeOnlyAfterSwitch == 1) && (w.latestSolidTrend == -3) {
				// tradeOnlyAfterSwitch==true but the trend has not switched: Don't trade
				logger.Debugln("Trend has not switched (still down). The setting \"tradeOnlyAfterSwitch==true\", so do not trade...")
				return
			}
			w.latestSolidTrend = -3

			if Option["disable_trading"] == "1" {
				logger.Infoln("Simulted SELL (Simulation only: no trade was made)")
			} else {
				logger.Infoln("Trend has switched, 探測到賣出點")
				go service.TriggerTrender("探測到賣出點")

				w.Do_sell(w.getTradePrice("sell"), tradeAmount)
			}
			//logger.Infoln("Trend is down, but no BTC to sell...");
		} else {
			logger.Debugf("Trend is down, but not for long enough (needs to be \"down\" for at least t %d samples)\n", TresholdLevel)
		}
	} else {
		logger.Debugln("Trend is undefined/weak")
	}
}
開發者ID:jackyxie,項目名稱:btcrobot,代碼行數:55,代碼來源:trend.go

示例2: RunCreateVm

func RunCreateVm(ctx context.Context, vmDeviceId uint) error {
	repo, ok := middleware.RepoFromContext(ctx)
	if !ok {
		return errors.New("內部服務器錯誤")
	}

	logger, ok := middleware.LoggerFromContext(ctx)
	if !ok {
		return errors.New("內部服務器錯誤")
	}

	vmDevice, err := repo.GetVmDeviceById(vmDeviceId)
	if err != nil {
		return err
	}

	device, err := repo.GetDeviceById(vmDevice.DeviceID)
	if err != nil {
		return err
	}

	var cmdFormat = `LANG=C virt-install --connect qemu+ssh://[email protected]%s/system \
--name=%s \
--os-type=windows \
--vcpus=%d \
--ram=%d \
--hvm \
--boot hd,network,menu=on \
--accelerate \
--graphics vnc,listen=0.0.0.0,port=%s \
--noautoconsole \
--autostart \
--network bridge=br0,model=virtio,mac=%s \
--disk path=/dev/VolGroup0/%s,device=disk,bus=virtio,cache=none,sparse=false,format=raw`
	var cmd = fmt.Sprintf(cmdFormat,
		device.Ip,
		vmDevice.Hostname,
		vmDevice.CpuCoresNumber,
		vmDevice.MemoryCurrent,
		vmDevice.VncPort,
		vmDevice.Mac,
		vmDevice.Hostname)
	logger.Debugf("create vm:%s", cmd)
	var runResult = "執行腳本:\n" + cmd
	bytes, err := util.ExecScript(cmd)
	logger.Debugf("create result:%s", string(bytes))
	runResult += "\n\n" + "執行結果:\n" + string(bytes)
	if err != nil {
		logger.Errorf("create error:%s", err.Error())
		runResult += "\n\n" + "錯誤信息:\n" + err.Error()
		return errors.New(runResult)
	}
	return nil
}
開發者ID:idcos,項目名稱:osinstall-server,代碼行數:54,代碼來源:vm_shell.go

示例3: RunCreateVol

func RunCreateVol(ctx context.Context, vmDeviceId uint) error {
	repo, ok := middleware.RepoFromContext(ctx)
	if !ok {
		return errors.New("內部服務器錯誤")
	}

	logger, ok := middleware.LoggerFromContext(ctx)
	if !ok {
		return errors.New("內部服務器錯誤")
	}

	conf, ok := middleware.ConfigFromContext(ctx)
	if !ok {
		return errors.New("內部服務器錯誤")
	}

	vmDevice, err := repo.GetVmDeviceById(vmDeviceId)
	if err != nil {
		return err
	}

	device, err := repo.GetDeviceById(vmDevice.DeviceID)
	if err != nil {
		return err
	}

	storage := conf.Vm.Storage
	if storage == "" {
		storage = "guest_images_lvm"
	}

	var cmdFormat = `LANG=C virsh --connect qemu+ssh://[email protected]%s/system vol-create-as %s %s %dG`
	var cmd = fmt.Sprintf(cmdFormat,
		device.Ip,
		storage,
		vmDevice.Hostname,
		vmDevice.DiskSize)
	logger.Debugf("vm create vol:%s", cmd)
	var runResult = "執行腳本:\n" + cmd
	bytes, err := util.ExecScript(cmd)
	logger.Debugf("create result:%s", string(bytes))
	runResult += "\n\n" + "執行結果:\n" + string(bytes)
	if err != nil {
		logger.Errorf("create error:%s", err.Error())
		runResult += "\n\n" + "錯誤信息:\n" + err.Error()
		return errors.New(runResult)
	}
	return nil
}
開發者ID:idcos,項目名稱:osinstall-server,代碼行數:49,代碼來源:vm_shell.go

示例4: PostComment

// 發表評論。入topics_reply庫,更新topics和topics_ex庫
// objname 注冊的評論對象名
func PostComment(objid, objtype, uid int, content string, objname string) error {
	comment := model.NewComment()
	comment.Objid = objid
	comment.Objtype = objtype
	comment.Uid = uid
	comment.Content = content

	// TODO:評論樓層怎麽處理,避免衝突?最後的樓層信息保存在內存中?

	// 暫時隻是從數據庫中取出最後的評論樓層
	stringBuilder := util.NewBuffer()
	stringBuilder.Append("objid=").AppendInt(objid).Append(" AND objtype=").AppendInt(objtype)
	tmpCmt, err := model.NewComment().Where(stringBuilder.String()).Order("ctime DESC").Find()
	if err != nil {
		logger.Errorln("post comment service error:", err)
		return err
	} else {
		comment.Floor = tmpCmt.Floor + 1
	}
	// 入評論庫
	cid, err := comment.Insert()
	if err != nil {
		logger.Errorln("post comment service error:", err)
		return err
	}
	// 回調,不關心處理結果(有些對象可能不需要回調)
	if commenter, ok := commenters[objname]; ok {
		logger.Debugf("評論[objid:%d] [objtype:%d] [uid:%d] 成功,通知被評論者更新", objid, objtype, uid)
		go commenter.UpdateComment(cid, objid, uid, time.Now().Format("2006-01-02 15:04:05"))
	}

	return nil
}
開發者ID:jimmykuu,項目名稱:studygolang,代碼行數:35,代碼來源:comment.go

示例5: Login

// 登錄;成功返回用戶登錄信息(user_login)
func Login(username, passwd string) (*model.UserLogin, error) {
	userLogin := model.NewUserLogin()
	err := userLogin.Where("username=" + username + " OR email=" + username).Find()
	if err != nil {
		logger.Errorf("用戶 %s 登錄錯誤:%s", username, err)
		return nil, errors.New("內部錯誤,請稍後再試!")
	}
	// 校驗用戶
	if userLogin.Uid == 0 {
		logger.Infof("用戶名 %s 不存在", username)
		return nil, ErrUsername
	}
	passcode := userLogin.GetPasscode()
	md5Passwd := util.Md5(passwd + passcode)
	logger.Debugf("passwd: %s, passcode: %s, md5passwd: %s, dbpasswd: %s", passwd, passcode, md5Passwd, userLogin.Passwd)
	if md5Passwd != userLogin.Passwd {
		logger.Infof("用戶名 %s 填寫的密碼錯誤", username)
		return nil, ErrPasswd
	}

	// 登錄,活躍度+1
	go IncUserWeight("uid="+strconv.Itoa(userLogin.Uid), 1)

	return userLogin, nil
}
開發者ID:philsong,項目名稱:studygolang,代碼行數:26,代碼來源:user.go

示例6: Increment

// Increment 增加/減少 某個字段的值
func (this *Dao) Increment(field string, num int) error {
	if num == 0 {
		return errors.New("dao Increment(`num`不能為0)")
	}
	where := this.where
	if where != "" {
		where = "WHERE " + where
	}
	setClause := fmt.Sprintf("`%s`=`%s`", field, field)
	if num > 0 {
		setClause += fmt.Sprintf("+%d", num)
	} else {
		setClause += fmt.Sprintf("-%d", num)
	}
	strSql := fmt.Sprintf("UPDATE `%s` SET %s %s", this.tablename, setClause, where)
	logger.Debugln("Increment sql:", strSql)
	err := this.Open()
	if err != nil {
		return err
	}
	defer this.Close()
	result, err := this.Exec(strSql, this.whereVal...)
	if err != nil {
		return err
	}
	affected, err := result.RowsAffected()
	if err != nil {
		return err
	}
	if affected == 0 {
		return errors.New("dao Increment 沒有更新任何數據!")
	}
	logger.Debugf("成功 increment `%s`表 %d 條記錄", this.tablename, affected)
	return nil
}
開發者ID:jimmykuu,項目名稱:studygolang,代碼行數:36,代碼來源:dao.go

示例7: parse_trade

func parse_trade(trades []interface{}, trades_data *[60]Trade) bool {
	for k, v := range trades {
		switch vt := v.(type) {
		case map[string]interface{}:
			logger.Debugln(k, " is a map:")
			logger.Debugf("trades[%d]\n", k)

			for ik, iv := range vt {
				switch ik {
				case "time":
					trades_data[k].Time = iv.(string)
				case "price":
					trades_data[k].Price = util.InterfaceToFloat64(iv)
				case "amount":
					trades_data[k].Amount = util.InterfaceToFloat64(iv)
				case "type":
					trades_data[k].Type = iv.(string)
				}
			}
		default:
			logger.Errorln(k, v)
			logger.Fatalln("don't know the type, crash!")
			return false
		}
	}
	return true
}
開發者ID:cnspot,項目名稱:btcrobot,代碼行數:27,代碼來源:orderbook.go

示例8: LoginHandler

// 登錄
// uri : /account/login
func LoginHandler(rw http.ResponseWriter, req *http.Request) {
	username := req.FormValue("username")
	if username == "" || req.Method != "POST" {
		req.Form.Set(filter.CONTENT_TPL_KEY, "/template/login.html")
		return
	}
	// 處理用戶登錄
	passwd := req.FormValue("passwd")
	userLogin, err := service.Login(username, passwd)
	if err != nil {
		req.Form.Set(filter.CONTENT_TPL_KEY, "/template/login.html")
		filter.SetData(req, map[string]interface{}{"username": username, "error": err.Error()})
		return
	}
	logger.Debugf("remember_me is %q\n", req.FormValue("remember_me"))
	// 登錄成功,種cookie
	setCookie(rw, req, userLogin.Username)

	// 支持跳轉到源頁麵
	uri := "/"
	values := filter.NewFlash(rw, req).Flashes("uri")
	if values != nil {
		uri = values[0].(string)
	}
	logger.Debugln("uri===", uri)
	util.Redirect(rw, req, uri)
}
開發者ID:jackyxie,項目名稱:btcrobot,代碼行數:29,代碼來源:account.go

示例9: parse_buy_sell

func parse_buy_sell(sells_buys []interface{}, sells_buys_data *[10]SellBuy) bool {
	for k, v := range sells_buys {
		switch vt := v.(type) {
		case map[string]interface{}:
			logger.Debugln(k, " is a map:")
			logger.Debugf("sells/buys[%d]\n", k)

			for ik, iv := range vt {
				switch ik {
				case "price":
					sells_buys_data[k].Price = util.InterfaceToFloat64(iv)
				case "level":
					sells_buys_data[k].Level = util.InterfaceToFloat64(iv)
				case "amount":
					sells_buys_data[k].Amount = util.InterfaceToFloat64(iv)
				}
			}
		default:
			logger.Errorln(k, v)
			logger.Fatalln("don't know the type, crash!")
			return false
		}
	}

	return true
}
開發者ID:cnspot,項目名稱:btcrobot,代碼行數:26,代碼來源:orderbook.go

示例10: parse_topsell

// just fuck the huobi old shit bug
func parse_topsell(topsells map[string]interface{}, topsells_data *[5]Top_buy_sell) bool {
	index := 4
	for k, v := range topsells {
		switch vt := v.(type) {
		case map[string]interface{}:
			logger.Debugln(k, " is a map:")
			logger.Debugf("topsells[%s]\n", k)

			for ik, iv := range vt {
				logger.Debugln(ik, iv)
				switch ik {
				case "price":
					topsells_data[index].Price = util.InterfaceToFloat64(iv)
				case "amount":
					topsells_data[index].Amount = util.InterfaceToFloat64(iv)
				case "level":
					topsells_data[index].Level = util.InterfaceToFloat64(iv)
				case "accu":
					topsells_data[index].Accu = util.InterfaceToFloat64(iv)
				}
			}

			index--

		default:
			logger.Errorln(k, v)
			logger.Fatalln("don't know the type, crash!")
			return false
		}
	}
	return true
}
開發者ID:cnspot,項目名稱:btcrobot,代碼行數:33,代碼來源:orderbook.go

示例11: Persist

// 持久化 entity 到數據庫
func (this *Dao) Persist(entity interface{}) error {
	strSql, args, err := genPersistParams(entity)

	if err != nil {
		logger.Errorln("Persist error:", err)
		return err
	}

	logger.Debugln("Persist sql:", strSql, ";args:", args)

	err = this.Open()
	if err != nil {
		return err
	}
	defer this.Close()
	result, err := this.Exec(strSql, args...)
	if err != nil {
		return err
	}
	affected, err := result.RowsAffected()
	if err != nil {
		return err
	}
	logger.Debugf("成功更新了`%s`表 %d 條記錄", this.tablename, affected)
	return nil
}
開發者ID:bluefchen,項目名稱:studygolang,代碼行數:27,代碼來源:dao.go

示例12: PostComment

// 發表評論(或回複)。
// objid 注冊的評論對象
// uid 評論人
func PostComment(uid, objid int, form url.Values) (*model.Comment, error) {
	comment := model.NewComment()
	comment.Objid = objid
	objtype := util.MustInt(form.Get("objtype"))
	comment.Objtype = objtype
	comment.Uid = uid
	comment.Content = form.Get("content")

	// TODO:評論樓層怎麽處理,避免衝突?最後的樓層信息保存在內存中?

	// 暫時隻是從數據庫中取出最後的評論樓層
	stringBuilder := util.NewBuffer()
	stringBuilder.Append("objid=").AppendInt(objid).Append(" AND objtype=").AppendInt(objtype)
	tmpCmt, err := model.NewComment().Where(stringBuilder.String()).Order("ctime DESC").Find()
	if err != nil {
		logger.Errorln("post comment service error:", err)
		return nil, err
	} else {
		comment.Floor = tmpCmt.Floor + 1
	}
	// 入評論庫
	cid, err := comment.Insert()
	if err != nil {
		logger.Errorln("post comment service error:", err)
		return nil, err
	}
	comment.Cid = cid
	comment.Ctime = util.TimeNow()
	decodeCmtContent(comment)

	// 回調,不關心處理結果(有些對象可能不需要回調)
	if commenter, ok := commenters[objtype]; ok {
		logger.Debugf("評論[objid:%d] [objtype:%d] [uid:%d] 成功,通知被評論者更新", objid, objtype, uid)
		go commenter.UpdateComment(cid, objid, uid, time.Now().Format("2006-01-02 15:04:05"))
	}

	// 發評論,活躍度+5
	go IncUserWeight("uid="+strconv.Itoa(uid), 5)

	// 給被評論對象所有者發係統消息
	ext := map[string]interface{}{
		"objid":   objid,
		"objtype": objtype,
		"cid":     cid,
		"uid":     uid,
	}
	go SendSystemMsgTo(0, objtype, ext)

	// @某人 發係統消息
	go SendSysMsgAtUids(form.Get("uid"), ext)
	go SendSysMsgAtUsernames(form.Get("usernames"), ext)

	return comment, nil
}
開發者ID:bluefchen,項目名稱:studygolang,代碼行數:57,代碼來源:comment.go

示例13: RunReStartVm

//restart vm
func RunReStartVm(ctx context.Context, vmDeviceId uint) error {
	repo, ok := middleware.RepoFromContext(ctx)
	if !ok {
		return errors.New("內部服務器錯誤")
	}

	logger, ok := middleware.LoggerFromContext(ctx)
	if !ok {
		return errors.New("內部服務器錯誤")
	}

	vmDevice, err := repo.GetVmDeviceById(vmDeviceId)
	if err != nil {
		return err
	}

	device, err := repo.GetDeviceById(vmDevice.DeviceID)
	if err != nil {
		return err
	}

	var cmdFormat = `LANG=C virsh --connect qemu+ssh://[email protected]%s/system 'destroy %s; start %s'`
	var cmd = fmt.Sprintf(cmdFormat,
		device.Ip,
		vmDevice.Hostname,
		vmDevice.Hostname)
	logger.Debugf("restart vm:%s", cmd)
	var runResult = "執行腳本:\n" + cmd
	bytes, err := util.ExecScript(cmd)
	logger.Debugf("restart result:%s", string(bytes))
	runResult += "\n\n" + "執行結果:\n" + string(bytes)
	if err != nil {
		logger.Errorf("restart error:%s", err.Error())
		runResult += "\n\n" + "錯誤信息:\n" + err.Error()
		return errors.New(runResult)
	}
	return nil
}
開發者ID:idcos,項目名稱:osinstall-server,代碼行數:39,代碼來源:vm_shell.go

示例14: LoginHandler

// 登錄
// uri : /account/login{json:(|.json)}
func LoginHandler(rw http.ResponseWriter, req *http.Request) {
	username := req.PostFormValue("username")
	if username == "" || req.Method != "POST" {
		filter.SetData(req, map[string]interface{}{"error": "非法請求"})
		req.Form.Set(filter.CONTENT_TPL_KEY, "/template/login.html")
		return
	}

	vars := mux.Vars(req)

	suffix := vars["json"]

	// 處理用戶登錄
	passwd := req.PostFormValue("passwd")
	userLogin, err := service.Login(username, passwd)
	if err != nil {
		if suffix != "" {
			logger.Errorln("login error:", err)
			fmt.Fprint(rw, `{"ok":0,"error":"`+err.Error()+`"}`)
			return
		}

		req.Form.Set(filter.CONTENT_TPL_KEY, "/template/login.html")
		filter.SetData(req, map[string]interface{}{"username": username, "error": err.Error()})
		return
	}
	logger.Debugf("remember_me is %q\n", req.FormValue("remember_me"))
	// 登錄成功,種cookie
	setCookie(rw, req, userLogin.Username)

	if suffix != "" {
		fmt.Fprint(rw, `{"ok":1,"msg":"success"}`)
		return
	}

	// 支持跳轉到源頁麵
	uri := "/"
	values := filter.NewFlash(rw, req).Flashes("uri")
	if values != nil {
		uri = values[0].(string)
	}
	logger.Debugln("uri===", uri)
	util.Redirect(rw, req, uri)
}
開發者ID:bluefchen,項目名稱:studygolang,代碼行數:46,代碼來源:account.go

示例15: Delete

func (this *Dao) Delete() error {
	strSql := util.DeleteSql(this)
	logger.Debugln("Delete sql:", strSql)
	err := this.Open()
	if err != nil {
		return err
	}
	defer this.Close()
	result, err := this.Exec(strSql, append(this.colValues, this.whereVal...)...)
	if err != nil {
		return err
	}
	affected, err := result.RowsAffected()
	if err != nil {
		return err
	}
	logger.Debugf("成功刪除了`%s`表 %d 條記錄", this.tablename, affected)
	return nil
}
開發者ID:xuzhiping7,項目名稱:studygolang,代碼行數:19,代碼來源:dao.go


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