本文整理汇总了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
}
示例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
}
示例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)
}
示例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
}
示例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
}
示例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
}
示例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
}
示例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
}
示例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
}
示例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)
}
示例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()
}
示例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)
}
}
}
示例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")
}
示例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
}
示例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
}