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


Golang logrus.Fatal函数代码示例

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


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

示例1: main

func main() {
	pflag.Parse()

	viper.SetConfigName("config")
	viper.AddConfigPath(".")

	if debug {
		logrus.SetLevel(logrus.DebugLevel)
	}

	if err := viper.ReadInConfig(); err != nil {
		logrus.Fatal(err)
	}

	nick := viper.GetString("twitch.nick")
	pass := viper.GetString("twitch.pass")
	channels := viper.GetStringSlice("twitch.join")
	dbFilename := viper.GetString("database.filename")
	superusers := viper.GetStringSlice("permissions.superusers")

	bot := bot.NewBot(nick, pass, channels, dbFilename, superusers)
	if err := bot.Start(); err != nil {
		logrus.Fatal(err)
	}

	c := make(chan os.Signal, 1)
	signal.Notify(c, os.Interrupt)
	<-c
	fmt.Print("\r\r\b")

	if err := bot.Stop(); err != nil {
		logrus.Fatal(err)
	}
}
开发者ID:jakebailey,项目名称:botzik,代码行数:34,代码来源:main.go

示例2: main

func main() {
	startTime := currentTimeMillis()

	transportFactory := thrift.NewTFramedTransportFactory(thrift.NewTTransportFactory())
	protocolFactory := thrift.NewTBinaryProtocolFactoryDefault()

	transport, err := thrift.NewTSocket(NETWORK_ADDR)
	if err != nil {
		logrus.Fatal(os.Stderr, "error resolving address:", err)
	}

	useTransport := transportFactory.GetTransport(transport)
	client := rpc.NewSessionManagerClientFactory(useTransport, protocolFactory)
	if err := transport.Open(); err != nil {
		logrus.Fatal(os.Stderr, "Error opening socket to "+NETWORK_ADDR, err)
	}
	defer transport.Close()

	// 开始调用服务的接口
	ctx := rpc.NewSessionContext()

	sid, _ := client.CreateSession(ctx)
	logrus.Infof("创新新的会话id => %s", sid)

	ctx, _ = client.GetSession(sid)
	logrus.Infof("获取会话上下文 => %+v", ctx)

	endTime := currentTimeMillis()
	logrus.Infof("本次调用用时: %d 毫秒", endTime-startTime)

}
开发者ID:ypyf,项目名称:golang-study,代码行数:31,代码来源:main.go

示例3: join

func join(c *cli.Context) {
	dflag := getDiscovery(c)
	if dflag == "" {
		log.Fatalf("discovery required to join a cluster. See '%s join --help'.", c.App.Name)
	}

	addr := c.String("advertise")
	if addr == "" {
		log.Fatal("missing mandatory --advertise flag")
	}
	if !checkAddrFormat(addr) {
		log.Fatal("--advertise should be of the form ip:port or hostname:port")
	}

	joinDelay, err := time.ParseDuration(c.String("delay"))
	if err != nil {
		log.Fatalf("invalid --delay: %v", err)
	}
	if joinDelay < time.Duration(0)*time.Second {
		log.Fatalf("--delay should not be a negative number")
	}

	hb, err := time.ParseDuration(c.String("heartbeat"))
	if err != nil {
		log.Fatalf("invalid --heartbeat: %v", err)
	}
	if hb < 1*time.Second {
		log.Fatal("--heartbeat should be at least one second")
	}
	ttl, err := time.ParseDuration(c.String("ttl"))
	if err != nil {
		log.Fatalf("invalid --ttl: %v", err)
	}
	if ttl <= hb {
		log.Fatal("--ttl must be strictly superior to the heartbeat value")
	}

	d, err := discovery.New(dflag, hb, ttl, getDiscoveryOpt(c))
	if err != nil {
		log.Fatal(err)
	}

	// if joinDelay is 0, no delay will be executed
	// if joinDelay is larger than 0,
	// add a random delay between 0s and joinDelay at start to avoid synchronized registration
	if joinDelay > 0 {
		r := rand.New(rand.NewSource(time.Now().UTC().UnixNano()))
		delay := time.Duration(r.Int63n(int64(joinDelay)))
		log.Infof("Add a random delay %s to avoid synchronized registration", delay)
		time.Sleep(delay)
	}

	for {
		log.WithFields(log.Fields{"addr": addr, "discovery": dflag}).Infof("Registering on the discovery service every %s...", hb)
		if err := d.Register(addr); err != nil {
			log.Error(err)
		}
		time.Sleep(hb)
	}
}
开发者ID:yehohanan7,项目名称:swarm,代码行数:60,代码来源:join.go

示例4: before

func before(c *cli.Context) error {
	initLogFormatter()
	initHelpAndVersionFlags()
	initAppHelpTemplate()

	// Log level
	if logLevel, err := log.ParseLevel(c.String(LogLevelKey)); err != nil {
		log.Fatal("[BITRISE_CLI] - Failed to parse log level:", err)
	} else {
		log.SetLevel(logLevel)
	}

	// Befor parsing cli, and running command
	// we need to decide wich path will be used by envman
	envman.CurrentEnvStoreFilePath = c.String(PathKey)
	if envman.CurrentEnvStoreFilePath == "" {
		if path, err := envStorePathInCurrentDir(); err != nil {
			log.Fatal("[ENVMAN] - Failed to set envman work path in current dir:", err)
		} else {
			envman.CurrentEnvStoreFilePath = path
		}
	}

	envman.ToolMode = c.Bool(ToolKey)
	if envman.ToolMode {
		log.Info("[ENVMAN] - Tool mode on")
	}

	if _, err := envman.GetConfigs(); err != nil {
		log.Fatal("[ENVMAN] - Failed to init configs:", err)
	}

	return nil
}
开发者ID:fbernardo,项目名称:envman,代码行数:34,代码来源:cli.go

示例5: decompress

func decompress() {
	log.Info("Decompressing Riak Explorer")

	var err error
	if err := os.Mkdir("riak_explorer", 0777); err != nil {
		log.Fatal("Unable to make rex directory: ", err)
	}

	asset, err := artifacts.Asset("trusty.tar.gz")
	if err != nil {
		log.Fatal(err)
	}
	if err = common.ExtractGZ("riak_explorer", bytes.NewReader(asset)); err != nil {
		log.Fatal("Unable to extract trusty root: ", err)
	}
	asset, err = artifacts.Asset("riak_explorer-bin.tar.gz")

	if err != nil {
		log.Fatal(err)
	}
	if err = common.ExtractGZ("riak_explorer", bytes.NewReader(asset)); err != nil {
		log.Fatal("Unable to extract rex: ", err)
	}

}
开发者ID:calebTomlinson,项目名称:riak-mesos,代码行数:25,代码来源:riak_explorer.go

示例6: main

func main() {
	err := jq.Init()
	if err != nil {
		log.Fatal(err)
	}

	log.WithFields(log.Fields{
		"version": jq.Version,
		"path":    jq.Path,
	}).Info("initialized jq")

	conf, err := config.Load()
	if err != nil {
		log.Fatal(err)
	}

	log.WithFields(log.Fields{
		"host": conf.Host,
		"port": conf.Port,
	}).Infof("Starting server at %s:%s", conf.Host, conf.Port)
	srv := server.New(conf)
	err = srv.Start()
	if err != nil {
		log.WithError(err).Fatal("error starting sever")
	}
}
开发者ID:jingweno,项目名称:jqplay,代码行数:26,代码来源:main.go

示例7: add

func add(c *cli.Context) {
	log.Debugln("[ENVMAN] - Work path:", envman.CurrentEnvStoreFilePath)

	key := c.String(KeyKey)
	expand := !c.Bool(NoExpandKey)
	replace := !c.Bool(AppendKey)

	var value string
	if stdinValue != "" {
		value = stdinValue
	} else if c.IsSet(ValueKey) {
		value = c.String(ValueKey)
	} else if c.String(ValueFileKey) != "" {
		if v, err := loadValueFromFile(c.String(ValueFileKey)); err != nil {
			log.Fatal("[ENVMAN] - Failed to read file value: ", err)
		} else {
			value = v
		}
	}

	if err := addEnv(key, value, expand, replace); err != nil {
		log.Fatal("[ENVMAN] - Failed to add env:", err)
	}

	log.Debugln("[ENVMAN] - Env added")

	if err := logEnvs(); err != nil {
		log.Fatal("[ENVMAN] - Failed to print:", err)
	}
}
开发者ID:bazscsa,项目名称:envman,代码行数:30,代码来源:add.go

示例8: logoutRegistry

func logoutRegistry(ctx *cobra.Command, args []string) {
	reg := client.INDEX_SERVER
	if len(args) > 0 {
		reg = args[0]
	}

	config, err := client.LoadConfig(configPath)
	if err != nil {
		log.Fatal(err)
	}

	registry, notFound := config.GetRegistry(reg)
	if (notFound != nil) || (registry.Credentials == "") {
		log.Fatalf("Not logged in to a Docker registry at %s", reg)
	}

	config.LogoutRegistry(reg)

	if err := config.SaveConfig(configPath); err != nil {
		log.Fatal(err)
	}

	ctx.Printf("Removed login credentials for a Docker registry at %s\n\n", reg)

	listRegistries(ctx, args)
}
开发者ID:ChengTiesheng,项目名称:talk2docker,代码行数:26,代码来源:registry.go

示例9: main

func main() {
	log.Info("Starting rancher-metadata")
	parseFlags()
	err := loadAnswers()
	if err != nil {
		log.Fatal("Cannot startup without a valid Answers file")
	}
	watchSignals()

	router.HandleFunc("/favicon.ico", http.NotFound)
	router.HandleFunc("/", root).
		Methods("GET", "HEAD").
		Name("Root")

	for _, version := range versions {
		router.HandleFunc("/{version:"+version+"}", metadata).
			Methods("GET", "HEAD").
			Name("Version:" + version)

		router.HandleFunc("/{version:"+version+"}/{key:.*}", metadata).
			Methods("GET", "HEAD").
			Name("Metadata")
	}

	log.Info("Listening on ", *listen)
	log.Fatal(http.ListenAndServe(*listen, router))
}
开发者ID:alena1108,项目名称:rancher-metadata,代码行数:27,代码来源:main.go

示例10: procesImage

func procesImage(path string, f os.FileInfo, err error) error {
	if f.IsDir() {
		return nil
	}

	log.Debugf("Processing %s", path)

	extension := filepath.Ext(f.Name())
	if !isSupportPhotoType(strings.ToLower(extension)) {
		log.Warnf("%s's file type %s is unsupported", path, extension)
		return nil
	}

	reader := exif.New()

	err = reader.Open(path)
	if err != nil {
		log.Fatal(err)
	}

	str := fmt.Sprintf("%s", reader.Tags["Date and Time"])
	t := f.ModTime()

	if len(str) == 0 {
		log.Warnf("Date and Time EXIF tag missing for %s", path)
	} else {
		layout := "2006:01:02 15:04:05"
		t, err = time.Parse(layout, str)
		if err != nil {
			log.Fatal(err)
		}
	}

	newDir := fmt.Sprintf("%s/%4d/%02d/%02d", destPath, t.Year(), t.Month(), t.Day())

	err = os.MkdirAll(newDir, 0777)
	if err != nil {
		log.Fatal(err)
	}

	newFile := fmt.Sprintf("%s/%s", newDir, f.Name())

	if mode == "move" {
		log.Debugf("Moving %s %s", path, newFile)
		err = os.Rename(path, newFile)
	} else {
		if _, err := os.Stat(newFile); err == nil {
			log.Warnf("Photo %s already exists", newFile)
		} else {
			log.Debugf("Copying %s %s", path, newFile)
			err = copyFile(path, newFile)
		}
	}

	if err != nil {
		log.Fatal(err)
	}

	return nil
}
开发者ID:ashmckenzie,项目名称:photoman,代码行数:60,代码来源:main.go

示例11: switchHost

func switchHost(ctx *cobra.Command, args []string) {
	if len(args) < 1 {
		ErrorExit(ctx, "Needs an argument <NAME> to switch")
	}

	name := args[0]

	config, err := client.LoadConfig(configPath)
	if err != nil {
		log.Fatal(err)
	}

	host, err := config.GetHost(name)
	if err != nil {
		log.Fatal(err)
	}

	config.Default = host.Name

	if err := config.SaveConfig(configPath); err != nil {
		log.Fatal(err)
	}

	listHosts(ctx, args)
}
开发者ID:ChengTiesheng,项目名称:talk2docker,代码行数:25,代码来源:host.go

示例12: loadFromMaster

func (m *Mesos) loadFromMaster(ip string, port string) (sj state.State) {
	url := "http://" + ip + ":" + port + "/master/state.json"

	req, err := http.NewRequest("GET", url, nil)
	req.Header.Set("Content-Type", "application/json")

	client := &http.Client{}
	resp, err := client.Do(req)
	if err != nil {
		log.Fatal(err)
	}

	defer resp.Body.Close()
	body, err := ioutil.ReadAll(resp.Body)
	if err != nil {
		log.Fatal(err)
	}

	err = json.Unmarshal(body, &sj)
	if err != nil {
		log.Fatal(err)
	}

	return sj
}
开发者ID:rncry,项目名称:mesos-consul,代码行数:25,代码来源:mesos.go

示例13: main

func (exp *exporter) main(c *cli.Context) {
	setupLogging(c)

	registry := newRegistry()

	collector, err := exp.Init(c, registry)
	if err != nil {
		log.Fatal(err)
	}

	if exp.Tick {
		collector.Collect(registry)
		interval := c.Int("interval")
		go func() {
			for _ = range time.Tick(time.Duration(interval) * time.Second) {
				if exp.ResetOnTick {
					registry.Reset()
				}
				collector.Collect(registry)
			}
		}()
	}

	http.HandleFunc("/", func(w http.ResponseWriter, req *http.Request) {
		w.Header().Add("Location", exp.MetricsPath)
		w.WriteHeader(http.StatusFound)
	})
	http.Handle(exp.MetricsPath, prometheus.Handler())
	if err := http.ListenAndServe(fmt.Sprintf(":%d", c.Int("port")), nil); err != nil {
		log.Fatal(err)
	}
}
开发者ID:kawamuray,项目名称:prometheus-exporter-harness,代码行数:32,代码来源:exporter.go

示例14: DeleteTestRun

// DeleteTestRun will remove an entire testrun entry from teh agent cache by UUID
func (ac AgentCache) DeleteTestRun(uuid string) error {

	// Open connection
	db, err := sql.Open("sqlite3", ac.db_loc)
	if err != nil {
		log.Error(err)
		return errors.New("Error accessing sqlite cache for DeleteTestRun")
	}
	defer db.Close()

	// Begin Update
	tx, err := db.Begin()
	if err != nil {
		log.Fatal(err)
		return errors.New("Error beginning new DeleteTestRun action")
	}

	stmt, err := tx.Prepare(fmt.Sprintf("delete from testruns where uuid = \"%s\" ", uuid))
	if err != nil {
		log.Fatal(err)
		return errors.New("Error preparing new DeleteTestRun action")
	}
	defer stmt.Close()
	_, err = stmt.Exec()
	if err != nil {
		log.Fatal(err)
		return errors.New("Error executing new DeleteTestRun action")
	}
	tx.Commit()

	return nil
}
开发者ID:twm1010,项目名称:todd,代码行数:33,代码来源:testruns.go

示例15: main

func main() {

	log.Info("starting NNTP server...")
	conf, err := config.Ensure("settings.json")
	if err != nil {
		log.Fatal(err)
	}

	if conf.Log == "debug" {
		log.SetLevel(log.DebugLevel)
	}

	serv := &nntp.Server{
		Config: conf.NNTP,
		Feeds:  conf.Feeds,
	}
	serv.Storage, err = store.NewFilesytemStorage(conf.Store.Path, false)
	if err != nil {
		log.Fatal(err)
	}
	l, err := net.Listen("tcp", conf.NNTP.Bind)
	if err != nil {
		log.Fatal(err)
	}
	log.Info("listening on ", l.Addr())
	err = serv.Serve(l)
	if err != nil {
		log.Fatal(err)
	}
}
开发者ID:majestrate,项目名称:nntpchan,代码行数:30,代码来源:main.go


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