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


Golang Logger.Logger类代码示例

本文整理汇总了Golang中Logger.Logger的典型用法代码示例。如果您正苦于以下问题:Golang Logger类的具体用法?Golang Logger怎么用?Golang Logger使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: 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

示例2: GetMetric

func GetMetric(params interface{}, log *logger.Logger) interface{} {

	difference := make(map[string]uint64)
	device := params.(string)
	device_type := getDeviceType(device)
	new_metrics := initLastMetrics(device)
	metrics, err := getDiskMetrics(device, device_type)

	if new_metrics {
		log.Log("debug", "New metrics, sending zeroes")
	}

	if err != nil {
		log.Log("crit", fmt.Sprintf("%s", err))
	}

	for metric, value := range metrics {
		if new_metrics {
			difference[metric] = 0
		} else {
			difference[metric] = value - readMetric(device, metric)
			if int64(value-readMetric(device, metric)) < 0 {
				difference[metric] = 0
			}
		}

		writeMetric(device, metric, value)
	}

	return difference
}
开发者ID:karlpilkington,项目名称:golang-devops-stuff,代码行数:31,代码来源:io_usage.go

示例3: readUnixSocket

func readUnixSocket(path string, log *logger.Logger) interface{} {
	fi, err := os.Stat(path)

	if err != nil && os.IsNotExist(err) {
		log.Log("crit", "Could not locate unix socket for json_poll at path: "+path)
		return nil
	}

	if fi.Mode()&os.ModeSocket != os.ModeSocket {
		log.Log("crit", path+" is not a unix socket for json_poll")
		return nil
	}

	client := &http.Client{
		Transport: &http.Transport{
			Dial: func(network, addr string) (net.Conn, error) {
				return net.Dial("unix", path)
			},
		},
	}

	req, _ := http.NewRequest("GET", "http://localhost", nil)
	req.Close = true
	return doRequest(req, client, log)
}
开发者ID:tomzhang,项目名称:golang-devops-stuff,代码行数:25,代码来源:json_poll.go

示例4: 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

示例5: 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

示例6: GetMetric

func GetMetric(params interface{}, log *logger.Logger) interface{} {
	var loadavg [3]C.double

	log.Log("debug", "Calling getloadavg()")

	C.getloadavg(&loadavg[0], 3)

	return loadavg
}
开发者ID:karlpilkington,项目名称:golang-devops-stuff,代码行数:9,代码来源:load_average.go

示例7: GetMetric

func GetMetric(params interface{}, log *logger.Logger) interface{} {
	res, err := gm.ProcessMemoryUsage(params.(string))

	if err != nil {
		log.Log("crit", err.Error())
		return nil
	}

	return res
}
开发者ID:WIZARD-CXY,项目名称:golang-devops-stuff,代码行数:10,代码来源:process_mem_usage.go

示例8: GetMetric

func GetMetric(params interface{}, log *logger.Logger) interface{} {
	result, err := gm.MemoryUsage()

	if err != nil {
		log.Log("crit", err.Error())
		return nil
	}

	return result
}
开发者ID:WIZARD-CXY,项目名称:golang-devops-stuff,代码行数:10,代码来源:mem_usage.go

示例9: GetMetric

func GetMetric(params interface{}, log *logger.Logger) interface{} {
	results, err := ioUsage.Metric(params.(string))

	if err != nil {
		log.Log("crit", err.Error())
		return nil
	}

	return results
}
开发者ID:WIZARD-CXY,项目名称:golang-devops-stuff,代码行数:10,代码来源:io_usage.go

示例10: readURL

func readURL(url string, log *logger.Logger) interface{} {
	req, err := http.NewRequest("GET", url, nil)
	req.Close = true

	if err != nil {
		log.Log("crit", fmt.Sprintf("URL '%s' is malformed: %s", url, err.Error()))
		return nil
	}

	return doRequest(req, &http.Client{}, log)
}
开发者ID:tomzhang,项目名称:golang-devops-stuff,代码行数:11,代码来源:json_poll.go

示例11: Start

func Start(listen string, config types.CirconusConfig, log *logger.Logger) error {
	go query.ResultPoller(config, log)

	log.Log("info", "Starting Web Service")

	s := &http.Server{
		Addr:    listen,
		Handler: &WebHandler{Config: config, Logger: log},
	}

	return s.ListenAndServe()
}
开发者ID:nkts,项目名称:golang-devops-stuff,代码行数:12,代码来源:web.go

示例12: ResultPoller

func ResultPoller(config types.CirconusConfig, log *logger.Logger) {
	log.Log("info", "Starting Result Poller")
	interval_duration := time.Second * time.Duration(config.PollInterval)

	for {
		start := time.Now()
		AllPlugins(config, log)
		duration := time.Now().Sub(start)

		if duration < interval_duration {
			time.Sleep(interval_duration - duration)
		}
	}
}
开发者ID:WIZARD-CXY,项目名称:golang-devops-stuff,代码行数:14,代码来源:query.go

示例13: AllPlugins

func AllPlugins(config types.CirconusConfig, log *logger.Logger) {
	rwmutex.Lock()
	defer rwmutex.Unlock()

	if pluginResults == nil {
		pluginResults = make(types.PluginResultCollection)
	}

	log.Log("debug", "Querying All Plugins")

	for key, _ := range config.Plugins {
		pluginResults[key] = Plugin(key, config, log)
	}

	log.Log("debug", "Done Querying All Plugins")
}
开发者ID:WIZARD-CXY,项目名称:golang-devops-stuff,代码行数:16,代码来源:query.go

示例14: Plugin

func Plugin(name string, config types.CirconusConfig, log *logger.Logger) types.PluginResult {
	log.Log("debug", fmt.Sprintf("Plugin %s Requested", name))

	item, ok := config.Plugins[name]

	if ok {
		t, ok := types.Plugins[item.Type]

		if ok {
			log.Log("debug", fmt.Sprintf("Plugin %s exists, running", name))
			return t(item.Params, log)
		}
	}

	return nil
}
开发者ID:WIZARD-CXY,项目名称:golang-devops-stuff,代码行数:16,代码来源:query.go

示例15: getJiffies

func getJiffies(log *logger.Logger) (jiffies int64, cpus int64) {
	content, err := ioutil.ReadFile("/proc/stat")

	if err != nil {
		log.Log("crit", fmt.Sprintf("While processing the cpu_usage package: %s"))
		return 0, 0
	}

	lines := strings.Split(string(content), "\n")

	for _, line := range lines {
		if strings.Index(line, "cpu ") == 0 {
			/* cpu with no number is the aggregate of all of them -- this is what we
			 * want to parse
			 */
			parts := strings.Split(line, " ")

			/* 2 - 11 are the time aggregates */
			for x := 2; x <= 11; x++ {

				/* 5 is the idle time, which we don't want */
				if x == 5 {
					continue
				}

				/* integer all the things */
				part, err := strconv.Atoi(parts[x])

				if err != nil {
					log.Log("crit", fmt.Sprintf("Could not convert integer from string while processing cpu_usage: %s", parts[x]))
					return 0, 0
				}

				jiffies += int64(part)
			}

		} else if strings.Index(line, "cpu") == 0 {
			/* cpu with a number is the specific time -- cheat and use this for the
			 * processor count since we've already read it
			 */
			cpus++
		}
	}

	return jiffies, cpus
}
开发者ID:karlpilkington,项目名称:golang-devops-stuff,代码行数:46,代码来源:cpu_usage.go


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