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


Golang logrus.WithField函数代码示例

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


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

示例1: Pause

// Pause kills the hashcat process and marks the job as paused
func (t *Tasker) Pause() error {
	log.WithField("task", t.job.UUID).Debug("Attempting to pause hashcat task")

	// Call status to update the job internals before pausing
	t.Status()

	if t.job.Status == common.STATUS_RUNNING {
		t.mux.Lock()

		if runtime.GOOS == "windows" {
			t.exec.Process.Kill()
		} else {
			io.WriteString(t.stdinPipe, "c")

			time.Sleep(1 * time.Second)

			io.WriteString(t.stdinPipe, "q")
		}

		t.mux.Unlock()

		// Wait for the program to actually exit
		t.doneWG.Wait()
	}

	// Change status to pause
	t.mux.Lock()
	t.job.Status = common.STATUS_PAUSED
	t.mux.Unlock()

	log.WithField("task", t.job.UUID).Debug("Task paused successfully")

	return nil
}
开发者ID:jmmcatee,项目名称:cracklord,代码行数:35,代码来源:tasker.go

示例2: updateQueue

// This is an internal function used to update the status of all Jobs.
// A LOCK SHOULD ALREADY BE HELD TO CALL THIS FUNCTION.
func (q *Queue) updateQueue() {
	// Loop through jobs and get the status of running jobs
	for i, _ := range q.stack {
		if q.stack[i].Status == common.STATUS_RUNNING {
			// Build status update call
			jobStatus := common.RPCCall{Job: q.stack[i]}

			err := q.pool[q.stack[i].ResAssigned].Client.Call("Queue.TaskStatus", jobStatus, &q.stack[i])
			// we care about the errors, but only from a logging perspective
			if err != nil {
				log.WithField("rpc error", err.Error()).Error("Error during RPC call.")
			}

			// Check if this is now no longer running
			if q.stack[i].Status != common.STATUS_RUNNING {
				// Release the resources from this change
				log.WithField("JobID", q.stack[i].UUID).Debug("Job has finished.")
				var hw string
				for _, v := range q.pool[q.stack[i].ResAssigned].Tools {
					if v.UUID == q.stack[i].ToolUUID {
						hw = v.Requirements
					}
				}
				q.pool[q.stack[i].ResAssigned].Hardware[hw] = true
			}
		}
	}
}
开发者ID:vaginessa,项目名称:cracklord,代码行数:30,代码来源:queue.go

示例3: TaskRun

func (q *Queue) TaskRun(rpc common.RPCCall, j *common.Job) error {
	log.WithField("task", rpc.Job.UUID).Debug("Attempting to run task")

	// Add a defered catch for panic from within the tools
	defer func() {
		if err := recover(); err != nil {
			log.Errorf("Recovered from Panic in Resource.TaskRun: %v", err)
		}
	}()

	// Grab the task specified by the UUID
	q.Lock()
	defer q.Unlock()
	log.WithField("Stack", q.stack).Debug("Stack")
	_, ok := q.stack[rpc.Job.UUID]

	// Check for a bad UUID
	if ok == false {
		log.WithField("task", rpc.Job.UUID).Debug("Task with UUID provided does not exist.")
		return errors.New("Task with UUID provided does not exist.")
	}

	// Start or resume the task
	err := q.stack[rpc.Job.UUID].Run()
	if err != nil {
		return err
	}

	*j = q.stack[rpc.Job.UUID].Status()

	log.WithField("task", j.UUID).Debug("Task ran successfully")

	return nil

}
开发者ID:vaginessa,项目名称:cracklord,代码行数:35,代码来源:resource.go

示例4: SizeList

// List all sizes.
func SizeList(c *cli.Context) {
	client := NewClient(c, DefaultConfig)
	opts := LoadOpts(c)

	f := func(opt *godo.ListOptions) ([]interface{}, *godo.Response, error) {
		list, resp, err := client.Sizes.List(opt)
		if err != nil {
			return nil, nil, err
		}

		si := make([]interface{}, len(list))
		for i := range list {
			si[i] = list[i]
		}

		return si, resp, err
	}

	si, err := PaginateResp(f, opts)
	if err != nil {
		logrus.WithField("err", err).Fatal("could not list sizes")
	}

	list := make([]godo.Size, len(si))
	for i := range si {
		list[i] = si[i].(godo.Size)
	}

	err = displayOutput(c, list)
	if err != nil {
		logrus.WithField("err", err).Fatal("could not write output")
	}
}
开发者ID:mattkanwisher,项目名称:doit,代码行数:34,代码来源:sizes.go

示例5: getHandler

func getHandler(w http.ResponseWriter, r *http.Request) *toadError {
	if r.Method == "GET" {
		log.Warn("Receiving GET file request")
		//take filename & send ask chain for hash
		params, err := parseURL(fmt.Sprintf("%s", r.URL))
		if err != nil {
			return &toadError{err, "error parsing URL", 400}
		}
		fileName := params["fileName"]

		log.WithField("=>", fileName).Warn("Looking for filename:")
		hash, err := tscore.GetInfos(fileName)
		if err != nil {
			return &toadError{err, "error getting namereg info", 400}
		}

		log.WithField("=>", hash).Warn("Found corresponding hash:")
		log.Warn("Getting it from IPFS...")
		contents, err := tscore.GetFile(fileName, hash)
		if err != nil {
			return &toadError{err, "error getting file", 400}
		}
		w.Write(contents) //outputfile

		if err := os.Remove(fileName); err != nil {
			return &toadError{err, "error removing file", 400}
		}

		log.Warn("Congratulations, you have successfully retreived you file from the toadserver")
	}
	return nil
}
开发者ID:eris-ltd,项目名称:toadserver,代码行数:32,代码来源:server.go

示例6: processMetrics

func processMetrics() {
	var (
		g    = metrics.NewGauge()
		fg   = metrics.NewGauge()
		memg = metrics.NewGauge()
	)
	metrics.DefaultRegistry.Register("goroutines", g)
	metrics.DefaultRegistry.Register("fds", fg)
	metrics.DefaultRegistry.Register("memory-used", memg)
	collect := func() {
		// update number of goroutines
		g.Update(int64(runtime.NumGoroutine()))
		// collect the number of open fds
		fds, err := osutils.GetOpenFds(os.Getpid())
		if err != nil {
			logrus.WithField("error", err).Error("containerd: get open fd count")
		}
		fg.Update(int64(fds))
		// get the memory used
		m := sigar.ProcMem{}
		if err := m.Get(os.Getpid()); err != nil {
			logrus.WithField("error", err).Error("containerd: get pid memory information")
		}
		memg.Update(int64(m.Size))
	}
	go func() {
		collect()
		for range time.Tick(30 * time.Second) {
			collect()
		}
	}()
}
开发者ID:Altiscale,项目名称:containerd,代码行数:32,代码来源:main.go

示例7: Quit

/*
	Stop the job running under this tool, don't forget to cleanup and file system
	resources, etc.
*/
func (v *johndictTasker) Quit() common.Job {
	log.WithField("Task", v.job.UUID).Debug("Attempting to quit johndict task.")

	// Update the jobs status
	log.Debug("Getting status before quit")
	v.Status()

	v.mux.Lock()

	// Kill the process after a SIGHUP
	log.Debug("Sending SIGHUP before process kill")
	v.cmd.Process.Signal(syscall.SIGHUP)
	log.Debug("Sending kill signal to process")
	v.cmd.Process.Kill()

	v.mux.Unlock()

	// Wait for the program to actually exit
	log.Debug("Waiting on the process to finish")
	<-v.doneWaitChan

	// Change the status to paused
	log.Debug("Change status")
	v.mux.Lock()
	v.job.Status = common.STATUS_QUIT
	v.mux.Unlock()

	log.WithField("Task", v.job.UUID).Debug("Task has been quit successfully.")

	return v.job
}
开发者ID:roo7break,项目名称:cracklord,代码行数:35,代码来源:johndict-tasker.go

示例8: getSValue

func (t *TownClient) getSValue() (sValue string) {
	log.WithField("tag", TAG).Info("getting sValue for town login")
	sValue = ""
	var doc *goquery.Document
	var e error
	log.WithField("tag", TAG).Infof("GET %v", ROOT)
	if doc, e = goquery.NewDocument(ROOT); e != nil {
		log.WithField("tag", TAG).Errorf("%s", e.Error())
		return
	}

	doc.Find("input").Each(func(i int, s *goquery.Selection) {
		attr, exists := s.Attr("name")
		if exists == true {
			if attr == "s" {
				bla, exists := s.Attr("value")
				if exists == true {
					sValue = bla
				}
			}
		}

	})
	log.WithField("tag", TAG).Infof("sValue: %v", sValue)
	return sValue
}
开发者ID:Kemonozume,项目名称:nzbcrawler,代码行数:26,代码来源:client.go

示例9: TestConnection

func (c couchPotato) TestConnection() bool {
	query := c.FullURL + "/app.available"
	resp, err := get(query)

	if err != nil {
		log.WithField("couchpotato.test", c).Error(err)
		return false
	}

	defer resp.Body.Close()

	if resp.StatusCode != http.StatusOK {
		log.WithField("couchpotato.test", c).Error(resp.Status)
		return false
	}

	var r couchPotato

	if err = json.NewDecoder(resp.Body).Decode(&r); err != nil {
		log.WithFields(log.Fields{
			"couchpotato.test": c,
			"reason":           "possibly bad api key",
		}).Error(err)
		return false
	}

	return r.Success
}
开发者ID:jrudio,项目名称:shart,代码行数:28,代码来源:couchpotato.go

示例10: GetDailyUrl

//return the Daily url or "" if something went wrong
func (t *TownClient) GetDailyUrl() (string, error) {
	log.WithField("tag", TAG).Info("getting Daily Url for town")

	req, err := http.NewRequest("GET", DAILY, nil)
	if err != nil {
		log.WithField("tag", TAG).Error(err.Error())
		return "", err
	}

	t.addHeader(req)

	if t.cookies != nil {
		for _, cookie := range t.cookies {
			req.AddCookie(cookie)
		}
	}

	resp, err := clientRed.Do(req)
	if resp == nil {
		return "", err
	}

	resp.Close = true
	defer resp.Body.Close()

	lv := resp.Header.Get("Location")
	if lv == "" {
		return "", errors.New("no Location header|most likely town annoucment")
	}

	return lv, nil
}
开发者ID:Kemonozume,项目名称:nzbcrawler,代码行数:33,代码来源:client.go

示例11: ThankPost

//execute ajax thank request for a post
func (t *TownClient) ThankPost(postid string, token string) (err error) {
	log.WithField("tag", TAG).Infof("thanking post %s", postid)

	param := url.Values{}
	param.Set("do", "thanks")
	param.Add("postid", postid)
	param.Add("securitytoken", token)
	param.Add("s", "")

	req, err := http.NewRequest("POST", THANKS, strings.NewReader(param.Encode()))
	if err != nil {
		return
	}

	log.WithField("tag", TAG).Infof("POST url: %v", THANKS)
	t.addHeader(req)
	if t.cookies != nil {
		for _, cookie := range t.cookies {
			req.AddCookie(cookie)
		}
	}

	resp, err := client.Do(req)
	if err != nil {
		return
	}

	resp.Close = true
	resp.Body.Close()
	return
}
开发者ID:Kemonozume,项目名称:nzbcrawler,代码行数:32,代码来源:client.go

示例12: Get

//http get using the given sUrl
func (t *TownClient) Get(sUrl string) (*http.Response, error) {
	log.WithField("tag", TAG).Infof("GET %v", sUrl)

	req, err := http.NewRequest("GET", sUrl, nil)
	if err != nil {
		log.WithField("tag", TAG).Errorf("couldn't create Request to: %v", sUrl)
		return nil, err
	}

	t.addHeader(req)

	if t.cookies != nil {
		for _, cookie := range t.cookies {
			req.AddCookie(cookie)
		}
	}

	//connect to sUrl
	resp, err := client.Do(req)
	if err != nil {
		log.WithField("tag", TAG).Errorf("couldn't connect to: %v", sUrl)
		return nil, err
	}

	return resp, nil
}
开发者ID:Kemonozume,项目名称:nzbcrawler,代码行数:27,代码来源:client.go

示例13: main

func main() {
	logger := logrus.WithFields(logrus.Fields{
		"gitcommit": GITCOMMIT,
	})

	logger.Info("Starting rancher-compose-executor")

	eventHandlers := map[string]events.EventHandler{
		"environment.create": handlers.CreateEnvironment,
		"ping": func(event *events.Event, apiClient *client.RancherClient) error {
			return nil
		},
	}

	router, err := events.NewEventRouter("rancher-compose-executor", 2000,
		os.Getenv("CATTLE_URL"),
		os.Getenv("CATTLE_ACCESS_KEY"),
		os.Getenv("CATTLE_SECRET_KEY"),
		nil, eventHandlers, "environment", 10)
	if err != nil {
		logrus.WithField("error", err).Fatal("Unable to create event router")
	}

	if err := router.Start(nil); err != nil {
		logrus.WithField("error", err).Fatal("Unable to start event router")
	}

	logger.Info("Exiting rancher-compose-executor")
}
开发者ID:alena1108,项目名称:rancher-compose-executor,代码行数:29,代码来源:main.go

示例14: runRecv

func runRecv(iterations int, profile bool) {
	if profile {
		f, err := os.Create("recv.profile")
		if err != nil {
			panic(err)
		}
		pprof.StartCPUProfile(f)
		defer pprof.StopCPUProfile()
		f, err = os.Create("recv.mem")
		if err != nil {
			panic(err)
		}
		defer func() {
			pprof.WriteHeapProfile(f)
			f.Close()
		}()
	}
	listener := newListener("", iterations)
	_, err := hyenad.NewHyenaClient(2, listener)
	if err != nil {
		panic(err)
	}
	log.WithField("Waiting for messages", iterations).Info("Receiving Client started")
	listener.wait.Wait()
	duration := time.Since(listener.startTime)
	msgPerS := float64(iterations) / float64(duration.Seconds())
	log.WithField("Messages", iterations).WithField("Time", duration.String()).WithField("Msg/S", msgPerS).Info("Done")
}
开发者ID:neuneu2k,项目名称:hyenad,代码行数:28,代码来源:testclient.go

示例15: ImagesListApplication

// ListApplication lists application iamges.
func ImagesListApplication(c *cli.Context) {
	client := NewClient(c, DefaultConfig)
	opts := LoadOpts(c)

	f := func(opt *godo.ListOptions) ([]interface{}, *godo.Response, error) {
		list, resp, err := client.Images.ListApplication(opt)
		if err != nil {
			return nil, nil, err
		}

		si := make([]interface{}, len(list))
		for i := range list {
			si[i] = list[i]
		}

		return si, resp, err
	}

	si, err := PaginateResp(f, opts)
	if err != nil {
		logrus.WithField("err", err).Fatal("could not list application images")
	}

	list := make([]godo.Image, len(si))
	for i := range si {
		list[i] = si[i].(godo.Image)
	}

	err = writeJSON(list, c.App.Writer)
	if err != nil {
		logrus.WithField("err", err).Fatal("could not write JSON")
	}
}
开发者ID:aybabtme,项目名称:doit,代码行数:34,代码来源:images.go


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