• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Golang logrus.WithError函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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


示例16: updateNameservers

// updateNameservers assigns each container the same nameservers as the host.
func updateNameservers(dk docker.Client, containers []db.Container) {
	hostResolv, err := ioutil.ReadFile("/etc/resolv.conf")
	if err != nil {
		log.WithError(err).Error("failed to read /etc/resolv.conf")
	}

	nsRE := regexp.MustCompile("nameserver\\s([0-9]{1,3}\\.){3}[0-9]{1,3}\\s+")
	matches := nsRE.FindAllString(string(hostResolv), -1)
	newNameservers := strings.Join(matches, "\n")

	for _, dbc := range containers {
		id := dbc.DockerID

		currNameservers, err := dk.GetFromContainer(id, "/etc/resolv.conf")
		if err != nil {
			log.WithError(err).Error("failed to get /etc/resolv.conf")
			return
		}

		if newNameservers != currNameservers {
			err = dk.WriteToContainer(id, newNameservers, "/etc",
				"resolv.conf", 0644)
			if err != nil {
				log.WithError(err).Error(
					"failed to update /etc/resolv.conf")
			}
		}
	}
}
开发者ID:yuenmeiwan,项目名称:quilt,代码行数:30,代码来源:worker.go


示例17: Connect

// Create a GCE cluster.
//
// Clusters are differentiated (namespace) by setting the description and
// filtering off of that.
//
// XXX: A lot of the fields are hardcoded.
func (clst *gceCluster) Connect(namespace string) error {
	if err := gceInit(); err != nil {
		log.WithError(err).Debug("failed to start up gce")
		return err
	}

	clst.projID = "declarative-infrastructure"
	clst.ns = namespace
	clst.imgURL = fmt.Sprintf(
		"%s/%s",
		computeBaseURL,
		"ubuntu-os-cloud/global/images/ubuntu-1510-wily-v20160310")
	clst.baseURL = fmt.Sprintf("%s/%s", computeBaseURL, clst.projID)
	clst.ipv4Range = "192.168.0.0/16"
	clst.intFW = fmt.Sprintf("%s-internal", clst.ns)
	clst.extFW = fmt.Sprintf("%s-external", clst.ns)

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

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

	return nil
}
开发者ID:yuenmeiwan,项目名称:quilt,代码行数:35,代码来源:gce.go


示例18: updateDefaultGw

func updateDefaultGw(odb ovsdb.Ovsdb) {
	currMac, err := getMac("", quiltBridge)
	if err != nil {
		log.WithError(err).Errorf("failed to get MAC for %s", quiltBridge)
		return
	}

	if currMac != gatewayMAC {
		if err := odb.SetBridgeMac(quiltBridge, gatewayMAC); err != nil {
			log.WithError(err).Error("failed to set MAC for default gateway")
		}
	}

	if err := upLink("", quiltBridge); err != nil {
		log.WithError(err).Error("failed to up default gateway")
	}

	currIPs, err := listIP("", quiltBridge)
	if err != nil {
		log.WithError(err).Errorf("failed to list IPs")
		return
	}

	targetIPs := []string{gatewayIP + "/8"}
	if err := updateIPs("", quiltBridge, currIPs, targetIPs); err != nil {
		log.WithError(err).Errorf("failed to update IPs")
	}
}
开发者ID:yuenmeiwan,项目名称:quilt,代码行数:28,代码来源:worker.go


示例19: main

func main() {
	configPathFlag := flag.String("config", "resource/config.yml", "A config file for start server")
	dbIPFlag := flag.String("dbip", "", "IP for database")
	flag.Parse()

	app := land.Application{}
	defer core.ErrorGlobalHandler()

	log.Info("Loading logger..")
	core.NewLogger()

	log.Info("Loading config..")
	if err := core.NewConfig(&app.Config, *configPathFlag); err != nil {
		log.WithError(err).Panic("Config is not load")
	}

	if *dbIPFlag != "" {
		app.Config.Database.IP = *dbIPFlag
	}

	log.Info("Loading database..")
	if err := core.NewDatabase(&app.Database, &app.Config); err != nil {
		log.WithError(err).Panic("Database is not load")
	}

	log.WithField("address", app.Config.Base.IP+":"+app.Config.Base.Port).Info("Server starting")
	if err := app.Run(); err != nil {
		log.WithError(err).Panic("Server is not started")
	}
}
开发者ID:dreamsxin,项目名称:noterius,代码行数:30,代码来源:main.go


示例20: updateOpenFlow

// Sets up the OpenFlow tables to get packets from containers into the OVN controlled
// bridge.  The Openflow tables are organized as follows.
//
//     - Table 0 will check for packets destined to an ip address of a label with MAC
//     0A:00:00:00:00:00 (obtained by OVN faking out arp) and use the OF mulipath action
//     to balance load packets across n links where n is the number of containers
//     implementing the label.  This result is stored in NXM_NX_REG0. This is done using
//     a symmetric l3/4 hash, so transport connections should remain intact.
//
//     -Table 1 reads NXM_NX_REG0 and changes the destination mac address to one of the
//     MACs of the containers that implement the label
//
// XXX: The multipath action doesn't perform well.  We should migrate away from it
// choosing datapath recirculation instead.
func updateOpenFlow(dk docker.Client, odb ovsdb.Ovsdb, containers []db.Container,
	labels []db.Label, connections []db.Connection) {
	targetOF, err := generateTargetOpenFlow(dk, odb, containers, labels, connections)
	if err != nil {
		log.WithError(err).Error("failed to get target OpenFlow flows")
		return
	}
	currentOF, err := generateCurrentOpenFlow(dk)
	if err != nil {
		log.WithError(err).Error("failed to get current OpenFlow flows")
		return
	}

	_, flowsToDel, flowsToAdd := join.HashJoin(currentOF, targetOF, nil, nil)

	for _, f := range flowsToDel {
		if err := deleteOFRule(dk, f.(OFRule)); err != nil {
			log.WithError(err).Error("error deleting OpenFlow flow")
		}
	}

	for _, f := range flowsToAdd {
		if err := addOFRule(dk, f.(OFRule)); err != nil {
			log.WithError(err).Error("error adding OpenFlow flow")
		}
	}
}
开发者ID:yuenmeiwan,项目名称:quilt,代码行数:41,代码来源:worker.go



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Golang logrus.WithField函数代码示例发布时间:2022-05-28
下一篇:
Golang logrus.Warnln函数代码示例发布时间:2022-05-28
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap