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


Golang logrus.WithError函数代码示例

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


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

示例1: renderHTML

func renderHTML(w http.ResponseWriter, r *http.Request, task eremetic.Task, taskID string, conf *config.Config) {
	var templateFile string

	data := make(map[string]interface{})
	funcMap := template.FuncMap{
		"ToLower":    strings.ToLower,
		"FormatTime": FormatTime,
	}

	if reflect.DeepEqual(task, (eremetic.Task{})) {
		notFound(w, r)
		return
	}

	templateFile = "task.html"
	data = makeMap(task)
	data["Version"] = version.Version

	source, _ := assets.Asset(fmt.Sprintf("templates/%s", templateFile))
	tpl, err := template.New(templateFile).Funcs(funcMap).Parse(string(source))

	if err != nil {
		http.Error(w, err.Error(), http.StatusInternalServerError)
		logrus.WithError(err).WithField("template", templateFile).Error("Unable to load template")
		return
	}

	err = tpl.Execute(w, data)
	if err != nil {
		logrus.WithError(err).WithField("template", templateFile).Error("Unable to execute template")
	}
}
开发者ID:klarna,项目名称:eremetic,代码行数:32,代码来源:helpers.go

示例2: Start

// Start begins periodic polling of Controller for the latest configuration. This is a blocking operation.
func (p *poller) Start() error {
	// Stop existing ticker if necessary
	if p.ticker != nil {
		if err := p.Stop(); err != nil {
			logrus.WithError(err).Error("Could not stop existing periodic poll")
			return err
		}
	}

	// Create new ticker
	p.ticker = time.NewTicker(p.config.Controller.Poll)

	// Do initial poll
	if err := p.poll(); err != nil {
		logrus.WithError(err).Error("Poll failed")
	}

	// Start periodic poll
	for _ = range p.ticker.C {
		if err := p.poll(); err != nil {
			logrus.WithError(err).Error("Poll failed")
		}
	}

	return nil
}
开发者ID:charshy,项目名称:sidecar,代码行数:27,代码来源:poller.go

示例3: main

func main() {
	flag.Parse()

	if *NAME == "" {
		log.Fatal("name required")
	}
	if *MEMORY == 0 {
		log.Fatal("memory required")
	}
	if *CPUS == 0 {
		log.Fatal("cpus required")
	}

	db, err := bolt.Open(*DB_PATH, 0600, nil)
	if err != nil {
		log.WithError(err).Fatal("failed to open database")
	}

	planrep := dal.NewBoltPlanrep(db)

	plan := &models.Plan{
		Name:     *NAME,
		Memory:   *MEMORY * 1024 * 1024,
		Cpus:     *CPUS,
		DiskSize: *DISK * 1024 * 1024 * 1024,
	}
	if err := planrep.Add(plan); err != nil {
		log.WithError(err).WithField("plan", plan).Fatal("failed to add ip address")
	}
}
开发者ID:subuk,项目名称:vmango,代码行数:30,代码来源:main.go

示例4: run

func (sv *supervisor) run(name string, args ...string) {
	isRunning, err := sv.dk.IsRunning(name)
	if err != nil {
		log.WithError(err).Warnf("could not check running status of %s.", name)
		return
	}
	if isRunning {
		return
	}

	ro := docker.RunOptions{
		Name:        name,
		Image:       images[name],
		Args:        args,
		NetworkMode: "host",
		VolumesFrom: []string{"minion"},
	}

	if name == Ovsvswitchd {
		ro.Privileged = true
	}

	log.Infof("Start Container: %s", name)
	_, err = sv.dk.Run(ro)
	if err != nil {
		log.WithError(err).Warnf("Failed to run %s.", name)
	}
}
开发者ID:NetSys,项目名称:quilt,代码行数:28,代码来源:supervisor.go

示例5: runApp

// Synchronize locally running "application" containers with the database.
func (sv *supervisor) runApp() {
	for range sv.conn.TriggerTick(10, db.MinionTable, db.ContainerTable).C {
		minion, err := sv.conn.MinionSelf()
		if err != nil || minion.Role != db.Worker {
			continue
		}

		if err := delStopped(sv.dk); err != nil {
			log.WithError(err).Error("Failed to clean up stopped containers")
		}

		dkcs, err := sv.dk.List(map[string][]string{
			"label": {docker.SchedulerLabelPair},
		})
		if err != nil {
			log.WithError(err).Error("Failed to list local containers.")
			continue
		}

		sv.conn.Transact(func(view db.Database) error {
			sv.runAppTransact(view, dkcs)
			return nil
		})
	}
}
开发者ID:yuenmeiwan,项目名称:quilt,代码行数:26,代码来源:supervisor.go

示例6: Run

// Run blocks implementing the scheduler module.
func Run(conn db.Conn, dk docker.Client) {
	bootWait(conn)

	subnet := getMinionSubnet(conn)
	err := dk.ConfigureNetwork(plugin.NetworkName, subnet)
	if err != nil {
		log.WithError(err).Fatal("Failed to configure network plugin")
	}

	loopLog := util.NewEventTimer("Scheduler")
	trig := conn.TriggerTick(60, db.MinionTable, db.ContainerTable,
		db.PlacementTable, db.EtcdTable).C
	for range trig {
		loopLog.LogStart()
		minion, err := conn.MinionSelf()
		if err != nil {
			log.WithError(err).Warn("Missing self in the minion table.")
			continue
		}

		if minion.Role == db.Worker {
			subnet = updateNetwork(conn, dk, subnet)
			runWorker(conn, dk, minion.PrivateIP, subnet)
		} else if minion.Role == db.Master {
			runMaster(conn)
		}
		loopLog.LogEnd()
	}
}
开发者ID:NetSys,项目名称:quilt,代码行数:30,代码来源:scheduler.go

示例7: main

func main() {
	containers, err := exec.Command("quilt", "containers").Output()
	if err != nil {
		log.WithError(err).Fatal("Unable to get containers.")
	}

	fmt.Println("`quilt containers` output:")
	fmt.Println(string(containers))

	matches := regexp.MustCompile(`(\d+) .*run master.*`).
		FindStringSubmatch(string(containers))
	if len(matches) != 2 {
		log.Fatal("Unable to find StitchID of Spark master.")
	}

	id := matches[1]
	logs, err := exec.Command("quilt", "logs", id).CombinedOutput()
	if err != nil {
		log.WithError(err).Fatal("Unable to get Spark master logs.")
	}

	fmt.Printf("`quilt logs %s` output:\n", id)
	fmt.Println(string(logs))

	if !strings.Contains(string(logs), "Pi is roughly") {
		fmt.Println("FAILED, sparkPI did not execute correctly.")
	} else {
		fmt.Println("PASSED")
	}
}
开发者ID:NetSys,项目名称:quilt,代码行数:30,代码来源:check_spark.go

示例8: updateContainerIP

func updateContainerIP(containers []db.Container, privateIP string, store Store) {

	oldIPMap := map[string]string{}
	selfStore := path.Join(nodeStore, privateIP)
	etcdIPs, err := store.Get(path.Join(selfStore, minionIPStore))
	if err != nil {
		etcdErr, ok := err.(client.Error)
		if !ok || etcdErr.Code != client.ErrorCodeKeyNotFound {
			log.WithError(err).Error("Failed to load current IPs from Etcd")
			return
		}
	}
	json.Unmarshal([]byte(etcdIPs), &oldIPMap)

	newIPMap := map[string]string{}
	for _, c := range containers {
		newIPMap[strconv.Itoa(c.StitchID)] = c.IP
	}

	if util.StrStrMapEqual(oldIPMap, newIPMap) {
		return
	}

	jsonData, err := json.Marshal(newIPMap)
	if err != nil {
		log.WithError(err).Error("Failed to marshal minion container IP map")
		return
	}

	err = store.Set(path.Join(selfStore, minionIPStore), string(jsonData), 0)
	if err != nil {
		log.WithError(err).Error("Failed to update minion container IP map")
	}
}
开发者ID:NetSys,项目名称:quilt,代码行数:34,代码来源:network.go

示例9: main

func main() {
	config, err := OpenConfig("config.yml")
	if err != nil {
		logrus.WithError(err).Fatal("Error loading config file")
	}

	logrus.Info("Loaded config")

	repo, err := rethink.NewRepo(config.RethinkDB)
	if err != nil {
		logrus.WithError(err).Fatal("Error connecting to repository")
	}

	logrus.Info("Connected to repository")

	tokenValidator := controllers.NewTokenValidator(config.Token.ClientID)
	updateController := controllers.NewUpdateController(repo, tokenValidator)
	readController := controllers.NewReadController(repo, tokenValidator)
	readAllController := controllers.NewReadAllController(repo, tokenValidator)
	subscribeController := controllers.NewSubscribeController(repo, tokenValidator)
	unsubscribeController := controllers.NewUnsubscribeController(repo, tokenValidator)

	http.Handle("/updates", updateController)
	http.Handle("/read", readController)
	http.Handle("/readall", readAllController)
	http.Handle("/subscribe", subscribeController)
	http.Handle("/unsubscribe", unsubscribeController)

	logrus.Info("Starting server")
	http.ListenAndServe(config.Server.Listen, nil)
}
开发者ID:gophergala2016,项目名称:blogalert,代码行数:31,代码来源:main.go

示例10: Run

// Run retrieves and prints the requested containers.
func (cCmd *Container) Run() int {
	localClient, err := cCmd.clientGetter.Client(cCmd.host)
	if err != nil {
		log.Error(err)
		return 1
	}
	defer localClient.Close()

	c, err := cCmd.clientGetter.LeaderClient(localClient)
	if err != nil {
		log.WithError(err).Error("Error connecting to leader.")
		return 1
	}
	defer c.Close()

	containers, err := c.QueryContainers()
	if err != nil {
		log.WithError(err).Error("Unable to query containers.")
		return 1
	}

	machines, err := localClient.QueryMachines()
	if err != nil {
		log.WithError(err).Error("Unable to query machines")
		return 1
	}

	writeContainers(os.Stdout, machines, containers)
	return 0
}
开发者ID:NetSys,项目名称:quilt,代码行数:31,代码来源:container.go

示例11: write

func (hc *HyenaClient) write() {
	stop := false
	for f := range hc.send {
		buf := f.Buffer()
		if !stop {
			size := byte(len(buf))
			n, err := hc.conn.Write([]byte{size})
			if err != nil || n != 1 {
				log.WithError(err).Error("Writing to hyenad client connection")
				hc.conn.Close()
				stop = true
			}
			n, err = hc.conn.Write(buf)
			if err != nil || n != len(buf) {
				log.WithError(err).Error("Writing to hyenad client connection")
				hc.conn.Close()
				stop = true
			}
			frameBuffers.Return(buf)
		} else {
			frameBuffers.Return(buf)
			log.WithField("Frame", f).Warn("Dropping frame, connection down")
		}
	}
}
开发者ID:neuneu2k,项目名称:hyenad,代码行数:25,代码来源:client.go

示例12: readloop

func (d *dialer) readloop(u *upstream) {
	for {
		if atomic.LoadInt32(&u.closed) != 0 {
			logrus.WithField("proto", u.proto).Warnln("dialer upstream is closed")
			return
		}
		p := packet{}
		switch u.proto {
		case tcp:
			err := u.decoder.Decode(&p)
			if err != nil {
				logrus.WithFields(logrus.Fields{
					"error": err,
				}).Warnln("Dialer docode upstream packet")
				return
			}
		case udp:
			udpbuf := make([]byte, buffersize)
			n, err := u.conn.Read(udpbuf)
			if err != nil {
				logrus.WithError(err).Warnln("dialer Read UDP error")
				return
			}
			if err := decodePacket(udpbuf[:n], &p); err != nil {
				logrus.WithError(err).Warnln("dialer gop decode from udp error")
				continue
			}
			p.udp = true
		}

		d.proc(u, &p)
	}
}
开发者ID:tomasen,项目名称:trafcacc,代码行数:33,代码来源:dialer.go

示例13: ChangeUserTestGroup

func (ab *abManager) ChangeUserTestGroup(userid, appid, testname string) (models.ABUser, error) {
	user, err := ab.User(userid)
	if err != nil {
		logrus.WithError(err).Errorf("User fetch failed")
		return user, err
	}
	repo := ab.db.GetABRepo()
	app, err := repo.App(appid)
	if err != nil {
		logrus.WithError(err).Errorf("App fetch failed")
		return user, err
	}
	version := int32(-1)
	if testname != "" {
		for _, t := range app.Tests {
			if t.Name == testname {
				version = app.Version
				break
			}
		}
	} else {
		version = app.Version
	}
	if version <= 0 {
		return user, grpc.Errorf(codes.InvalidArgument, "invalid test group name")
	}
	if err := repo.ChangeTesterInfo(userid, appid, testname, version); err != nil {
		logrus.WithError(err).Errorf("failed to change user testing info appid=%s to %s", appid, testname)
		return user, err
	}
	return ab.User(userid)
}
开发者ID:otsimo,项目名称:distribution,代码行数:32,代码来源:ab.go

示例14: Start

func (sys *System) Start() {
	backends := make(map[edn.Keyword]*Backend)

	for name, config := range sys.config.Backends {
		backend, err := NewBackend(sys, string(name), config)
		if err != nil {
			log.WithError(err).Fatal("Can't start backend")
			os.Exit(1)
		}
		backends[name] = backend
	}

	for _, config := range sys.config.Frontends {
		switch string(config.Type) {
		case "zmq":
			backend, pst := backends[config.Backend]
			if !pst {
				log.Fatalf("There are no backend %s", config.Backend)
				os.Exit(1)
			}
			_, err := NewZMQFrontend(sys, config, backend)
			if err != nil {
				log.WithError(err).Fatal("Can't start frontend")
				os.Exit(1)
			}
		case "http":
			NewHttpFrontend(sys, config.Endpoint)
		}
	}

	sys.processes.Wait()
}
开发者ID:prepor,项目名称:lucky,代码行数:32,代码来源:system.go

示例15: New

// New creates a GCE cluster.
//
// Clusters are differentiated (namespace) by setting the description and
// filtering off of that.
func New(namespace string) (*Cluster, error) {
	if err := gceInit(); err != nil {
		log.WithError(err).Debug("failed to start up gce")
		return nil, err
	}

	clst := Cluster{
		projID:    "declarative-infrastructure",
		ns:        namespace,
		ipv4Range: "192.168.0.0/16",
	}
	clst.baseURL = fmt.Sprintf("%s/%s", computeBaseURL, clst.projID)
	clst.intFW = fmt.Sprintf("%s-internal", clst.ns)
	clst.imgURL = fmt.Sprintf("%s/%s", computeBaseURL,
		"ubuntu-os-cloud/global/images/ubuntu-1604-xenial-v20160921")

	if err := clst.netInit(); err != nil {
		log.WithError(err).Debug("failed to start up gce network")
		return nil, err
	}

	if err := clst.fwInit(); err != nil {
		log.WithError(err).Debug("failed to start up gce firewalls")
		return nil, err
	}

	return &clst, nil
}
开发者ID:NetSys,项目名称:quilt,代码行数:32,代码来源:google.go


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