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


Golang Logger.Errorf方法代碼示例

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


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

示例1: NewRepo

// NewRepo 創建mysql數據實現實例
func NewRepo(conf *config.Config, log logger.Logger) (*MySQLRepo, error) {
	var connection string
	if conf.Repo.ConnectionIsCrypted != "" {
		str, err := util.RSADecrypt(conf.Rsa.PrivateKey, conf.Repo.ConnectionIsCrypted)
		if err != nil {
			return nil, err
		}
		connection = str
	} else if conf.Repo.Connection != "" {
		connection = conf.Repo.Connection
	}

	if connection == "" {
		return nil, errors.New("請先配置好數據庫連接信息!")
	}

	db, err := gorm.Open("mysql", connection)
	if err != nil {
		log.Errorf("database connection failed:%s", err.Error())
		return nil, err
	}
	db.LogMode(true)
	repo := &MySQLRepo{
		conf: conf,
		log:  log,
		db:   &db,
	}

	return repo, nil
}
開發者ID:idcos,項目名稱:osinstall-server,代碼行數:31,代碼來源:repo.go

示例2: RunGetVmHostPoolInfo

//get vm pool info
func RunGetVmHostPoolInfo(repo model.Repo, logger logger.Logger, conf *config.Config, deviceId uint) (string, error) {
	device, err := repo.GetDeviceById(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 pool-info %s`
	var cmd = fmt.Sprintf(cmdFormat,
		device.Ip,
		storage)
	logger.Debugf("get vm host pool info:%s", cmd)
	var runResult = "執行腳本:\n" + cmd
	bytes, err := util.ExecScript(cmd)
	logger.Debugf("result:%s", string(bytes))
	runResult += "\n\n" + "執行結果:\n" + string(bytes)
	if err != nil {
		logger.Errorf("error:%s", err.Error())
		runResult += "\n\n" + "錯誤信息:\n" + err.Error()
		return "", errors.New(runResult)
	}
	return string(bytes), nil
}
開發者ID:idcos,項目名稱:osinstall-server,代碼行數:28,代碼來源:vm_shell.go

示例3: RunGetVmInfo

//get vm info
func RunGetVmInfo(repo model.Repo, logger logger.Logger, vmDeviceId uint) (string, error) {
	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 dominfo %s`
	var cmd = fmt.Sprintf(cmdFormat,
		device.Ip,
		vmDevice.Hostname)
	logger.Debugf("get vm info:%s", cmd)
	var runResult = "執行腳本:\n" + cmd
	bytes, err := util.ExecScript(cmd)
	logger.Debugf("result:%s", string(bytes))
	runResult += "\n\n" + "執行結果:\n" + string(bytes)
	if err != nil {
		logger.Errorf("error:%s", err.Error())
		runResult += "\n\n" + "錯誤信息:\n" + err.Error()
		return "", errors.New(runResult)
	}
	return string(bytes), nil
}
開發者ID:idcos,項目名稱:osinstall-server,代碼行數:28,代碼來源:vm_shell.go

示例4: RunDeleteVmNoVncTokenFile

//delete noVNC token file
func RunDeleteVmNoVncTokenFile(repo model.Repo, logger logger.Logger, vmDeviceId uint) error {
	vmDevice, err := repo.GetVmDeviceById(vmDeviceId)
	if err != nil {
		return err
	}

	var dir = "/etc/cloudboot-server/novnc-tokens"
	var file = vmDevice.Hostname
	logger.Debugf("delete vm novnc token file:%s", dir+"/"+file)
	if util.FileExist(dir + "/" + file) {
		err := os.Remove(dir + "/" + file)
		if err != nil {
			logger.Errorf("error:%s", err.Error())
			return err
		}
	}
	return nil
}
開發者ID:idcos,項目名稱:osinstall-server,代碼行數:19,代碼來源:vm_shell.go

示例5: RunCreateVmNoVncTokenFile

//create noVNC token file
func RunCreateVmNoVncTokenFile(repo model.Repo, logger logger.Logger, vmDeviceId uint) error {
	vmDevice, err := repo.GetVmDeviceById(vmDeviceId)
	if err != nil {
		return err
	}

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

	var newHostname = strings.Replace(vmDevice.Hostname, ":", "_", -1)
	var strFormat = `%s: %s:%s`
	var str = fmt.Sprintf(strFormat,
		newHostname,
		device.Ip,
		vmDevice.VncPort)

	var dir = "/etc/cloudboot-server/novnc-tokens"
	var file = vmDevice.Hostname

	if !util.FileExist(dir) {
		err := os.MkdirAll(dir, 0777)
		if err != nil {
			return err
		}
	}
	//文件已存在,先刪除
	if util.FileExist(dir + "/" + file) {
		err := os.Remove(dir + "/" + file)
		if err != nil {
			return err
		}
	}
	logger.Debugf("create vm novnc token file %s:%s", dir+"/"+file, str)
	bytes := []byte(str)
	errCreate := ioutil.WriteFile(dir+"/"+file, bytes, 0644)
	if errCreate != nil {
		logger.Errorf("error:%s", errCreate.Error())
		return errCreate
	}
	return nil
}
開發者ID:idcos,項目名稱:osinstall-server,代碼行數:44,代碼來源:vm_shell.go

示例6: RunTestConnectVmHost

//test connect vm host
func RunTestConnectVmHost(repo model.Repo, logger logger.Logger, deviceId uint) (string, error) {
	device, err := repo.GetDeviceById(deviceId)
	if err != nil {
		return "", err
	}

	var cmdFormat = `LANG=C ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -o BatchMode=yes -o ConnectTimeout=3 [email protected]%s 'w'`
	var cmd = fmt.Sprintf(cmdFormat,
		device.Ip)
	logger.Debugf("test connect vm host:%s", cmd)
	var runResult = "執行腳本:\n" + cmd
	bytes, err := util.ExecScript(cmd)
	logger.Debugf("result:%s", string(bytes))
	runResult += "\n\n" + "執行結果:\n" + string(bytes)
	if err != nil {
		logger.Errorf("error:%s", err.Error())
		runResult += "\n\n" + "錯誤信息:\n" + err.Error()
		return "", errors.New(runResult)
	}
	return string(bytes), nil
}
開發者ID:idcos,項目名稱:osinstall-server,代碼行數:22,代碼來源:vm_shell.go


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