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

Golang logrus.SetLevel函数代码示例

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

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



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

示例1: getTestApi

// Returns a singleton instance of API, intialised with an empty DB containing a
// single user and a silent version of ClassicMartini
func getTestApi() API {
	if test_api != nil {
		return test_api
	}

	// Set Log level here. This should only be called once, and near the start
	// of the test run
	if !*verboseMartini {
		log.SetLevel(log.ErrorLevel)
	} else {
		log.SetLevel(log.DebugLevel)
	}

	db := getTestDb()
	a := New(Options{JwtKey: "RandomString", Db: db, Martini: getSilentMartini()})

	a.AddDefaultRoutes(&PrivateWidget{}, RouteOptions{Authenticate: true})
	a.AddDefaultRoutes(&Widget{})
	a.AddDefaultRoutes(&VerifiedWidget{})
	a.AddDefaultRoutes(&Widget{}, RouteOptions{UriModelName: "other_widgets"})

	a.AddDefaultRoutes(&User{})
	a.SetAuth(&User{}, "/auth")

	test_api = a
	return a
}
开发者ID:ivanol,项目名称:go-martini-api,代码行数:29,代码来源:helpers_test.go


示例2: main

func main() {
	config, err := core.ParseConfig("./config.yaml")
	if err != nil {
		logrus.Errorf("Failed to parse configuration: %s", err)
		return
	}

	switch core.Global.Logging {
	case "debug":
		logrus.SetLevel(logrus.DebugLevel)
	case "info":
		logrus.SetLevel(logrus.InfoLevel)
	case "warn":
		logrus.SetLevel(logrus.WarnLevel)
	case "error":
		logrus.SetLevel(logrus.ErrorLevel)
	default:
		logrus.SetLevel(logrus.InfoLevel)
		logrus.Warnf("Home: invalid log level supplied: '%s'", core.Global.Logging)
	}

	c := make(chan os.Signal, 1)
	signal.Notify(c, os.Interrupt)
	go func() {
		for sig := range c {
			_ = sig
			eventbus.EventBus.Publish(eventbus.Event{
				Topic:  eventbus.HOME_SHUTDOWN,
				Origin: "home",
			})
		}
	}()

	logrus.Infof("[Home] Geo-Location set to: Lat=%f Long=%f", core.Global.Latitude, core.Global.Longitude)

	service.ServiceRegistry.Register(&backend.Component{
		Name: "core",
	}, "shutdown_home", "Shutdown home", shutdownHome, map[string]string{}, map[string]string{})

	eventbus.EventBus.Start()

	backendConfig, _ := config.List("backends")
	backend.DefaultManager.StartBackendsByConfig(backendConfig)

	eventbus.EventBus.Subscribe(eventbus.HOME_SHUTDOWN, func(event eventbus.Event) {
		backend.DefaultManager.StopBackends()
	})

	core.PluginManager.Start(config)

	core.StateTracker.Start()
	service.ServiceRegistry.Start()

	eventbus.EventBus.Publish(eventbus.Event{
		Topic:  eventbus.HOME_STARTED,
		Origin: "home",
	})

	eventbus.EventBus.Wait()
}
开发者ID:nethack42,项目名称:go-home,代码行数:60,代码来源:main.go


示例3: main

func main() {

	app := cli.NewApp()

	app.Name = "pipes_api"
	app.Author = "Francis Bouvier <[email protected]>"
	app.Version = "0.1.0"
	app.Usage = "API for pipes, micro-services framework"
	app.Flags = []cli.Flag{logLevelFlag}

	app.Action = func(c *cli.Context) {
		switch c.String("log") {
		case "debug":
			log.SetLevel(log.DebugLevel)
		case "warn":
			log.SetLevel(log.WarnLevel)
		default:
			log.SetLevel(log.InfoLevel)
		}

		storeAddr := c.Args()[0]
		projectID := c.Args()[1]
		addr := "0.0.0.0:8080"
		if err := launch(storeAddr, projectID, addr); err != nil {
			log.Fatalln(err)
		}
	}
	app.Run(os.Args)
}
开发者ID:zanhsieh,项目名称:pipes,代码行数:29,代码来源:main.go


示例4: InitLog

// InitLog initializes the logrus logger
func InitLog(logLevel, formatter string) error {

	switch formatter {
	case LogStashFormatter:
		logrus.SetFormatter(&logstash.LogstashFormatter{
			TimestampFormat: time.RFC3339,
		})
	default:
		logrus.SetFormatter(&logrus.TextFormatter{
			ForceColors:   true,
			FullTimestamp: true,
		})
	}

	logrus.SetOutput(os.Stdout)

	level, err := logrus.ParseLevel(logLevel)

	if err != nil {
		logrus.SetLevel(logrus.DebugLevel)
		return err
	}

	logrus.SetLevel(level)
	return nil
}
开发者ID:sebastienfr,项目名称:handsongo,代码行数:27,代码来源:logger.go


示例5: ParseArgs

func ParseArgs(config *Config) {
	configfile := flag.String("config", "etc/ssologin.json", "config file (JSON)")
	flag.BoolVar(&config.Debug, "debug", false, "Debug-level output")
	flag.Parse()

	// Read the config file
	c, err := ioutil.ReadFile(*configfile)
	CheckError(err)

	// Unmarshal the config file
	err = json.Unmarshal(c, &config)
	CheckError(err)

	// Convert Expiration (int) to time type
	config.Expiry = time.Duration(config.Expiration) * time.Second

	// Set appropriate log-level
	if config.Debug {
		log.SetLevel(log.DebugLevel)
	} else {
		log.SetLevel(log.InfoLevel)
	}

	privkey, err := ssocookie.ReadECCPrivateKeyPem(config.Privkeyfile)
	CheckError(err)
	config.Privkey = privkey
}
开发者ID:heipei,项目名称:nginx-sso,代码行数:27,代码来源:ssologin.go


示例6: main

func main() {
	app := cli.NewApp()
	app.Name = path.Base(os.Args[0])
	app.Usage = "An entropy and failure injection management API for Docker platforms."
	app.Version = VERSION
	app.Authors = []cli.Author{{Name: "Jeff Nickoloff", Email: "[email protected]"}}
	app.Flags = flags
	app.Commands = commands
	app.Before = func(c *cli.Context) error {
		log.SetOutput(os.Stderr)
		level, err := log.ParseLevel(c.String("log-level"))
		if err != nil {
			log.Fatalf(err.Error())
		}
		log.SetLevel(level)

		// If a log level wasn't specified and we are running in debug mode,
		// enforce log-level=debug.
		if !c.IsSet("log-level") && !c.IsSet("l") && c.Bool("debug") {
			log.SetLevel(log.DebugLevel)
		}

		return nil
	}

	if err := app.Run(os.Args); err != nil {
		log.Fatal(err)
	}
}
开发者ID:ZhukovAlexander,项目名称:entropy,代码行数:29,代码来源:main.go


示例7: main

func main() {

	flag.Parse()
	cpus := runtime.NumCPU()
	runtime.GOMAXPROCS(cpus)

	log.SetFormatter(&log.JSONFormatter{})
	log.SetOutput(os.Stderr)
	if *env == "production" {
		log.SetLevel(log.WarnLevel)
	} else {
		log.SetLevel(log.DebugLevel)
	}
	log.Infoln("Starting server...")

	// load config
	d, err := ioutil.ReadFile(*configFile)
	if err != nil {
		log.Fatalln("[ERROR] read config.yml", err)
	}

	cfg, err := config.Load(bytes.NewReader(d), *env)
	if err != nil {
		log.Fatalln("[ERROR] config Load", err)
	}
	psAll := sphinx.NewSphinx(cfg.PSConfig, cpus)

	ctx := context.Background()
	ctx = sphinx.NewContext(ctx, psAll)
	kami.Context = ctx
	kami.Serve()
}
开发者ID:shunsukeaihara,项目名称:sphinx-httpserver,代码行数:32,代码来源:main.go


示例8: main

func main() {

	need_help := flag.Bool("h", false, "Show help")
	is_server := flag.Bool("s", false, "Run as server")
	verbose := flag.Bool("v", false, "More verbose output")
	cpuprofile := flag.String("cpuprofile", "", "Write cpu profile to file")
	flag.Parse()

	log.SetFormatter(&LogFormatter{&log.TextFormatter{
		FullTimestamp:   true,
		TimestampFormat: time.RFC822,
	}, "JUSTVPN"})
	log.SetLevel(log.InfoLevel)
	if *verbose {
		log.SetLevel(log.DebugLevel)
	}
	if *need_help {
		fmt.Printf("Usage: %v [OPTIONS] config.json\n", os.Args[0])
		flag.PrintDefaults()
		os.Exit(0)
	}
	if *is_server {
		log.Info("Running as server!")
	}
	if *cpuprofile != "" {
		log.Info("Saving CPU profile to %v", *cpuprofile)
		if f, err := os.Create(*cpuprofile); err != nil {
			log.Fatal(err)
		} else {
			pprof.StartCPUProfile(f)
			defer pprof.StopCPUProfile()
		}
	}

	if flag.NArg() == 0 {
		log.Fatal("Config file missing")
	}

	json_content, err := ioutil.ReadFile(flag.Arg(0))
	if err != nil {
		log.WithField("filename", flag.Arg(0)).Fatal("Error reading config file")
	}

	vpn := justvpn.VPN{}
	defer vpn.Destroy()
	if err = vpn.Init(*is_server, json_content); err != nil {
		log.WithField("error", err).Error("Error initing VPN")
		return
	}

	vpn.Start()

	signal_chan := make(chan os.Signal, 1)
	signal.Notify(signal_chan, os.Interrupt)

	select {
	case <-signal_chan:
		fmt.Println("CTRL-C Pressed")
	}
}
开发者ID:blahgeek,项目名称:justvpn,代码行数:60,代码来源:main.go


示例9: InitializeLogger

func InitializeLogger(developerModeFlag bool) {
	logger = log.New()

	if developerModeFlag {
		customFormatter := new(log.TextFormatter)
		customFormatter.FullTimestamp = true
		customFormatter.TimestampFormat = "2006-01-02 15:04:05"
		log.SetFormatter(customFormatter)

		log.SetLevel(log.DebugLevel)
		logger.Level = log.DebugLevel
		logger.Formatter = customFormatter
	} else {
		customFormatter := new(log.JSONFormatter)
		customFormatter.TimestampFormat = "2006-01-02 15:04:05"

		log.SetFormatter(customFormatter)
		customFormatter.DisableTimestamp = false

		log.SetLevel(log.InfoLevel)
		logger.Level = log.InfoLevel
		logger.Formatter = customFormatter
	}

	logger.Out = os.Stdout

}
开发者ID:Ritsyy,项目名称:almighty-core,代码行数:27,代码来源:log.go


示例10: NewCustomizedLogger

func NewCustomizedLogger(level string, developerModeFlag bool) (*log.Logger, error) {
	logger := log.New()

	lv, err := log.ParseLevel(level)
	if err != nil {
		return nil, err
	}
	logger.Level = lv

	if developerModeFlag {
		customFormatter := new(log.TextFormatter)
		customFormatter.FullTimestamp = true
		customFormatter.TimestampFormat = "2006-01-02 15:04:05"
		log.SetFormatter(customFormatter)

		log.SetLevel(log.DebugLevel)
		logger.Level = lv
		logger.Formatter = customFormatter
	} else {
		customFormatter := new(log.JSONFormatter)
		customFormatter.TimestampFormat = "2006-01-02 15:04:05"

		log.SetFormatter(customFormatter)
		customFormatter.DisableTimestamp = false

		log.SetLevel(log.InfoLevel)
		logger.Level = lv
		logger.Formatter = customFormatter
	}

	logger.Out = os.Stdout

	return logger, nil
}
开发者ID:Ritsyy,项目名称:almighty-core,代码行数:34,代码来源:log.go


示例11: TestRunWithTimeoutFailed

func TestRunWithTimeoutFailed(t *testing.T) {

	log.SetLevel(log.DebugLevel)
	defer log.SetLevel(log.InfoLevel)

	tmp, _ := ioutil.TempFile("", "tmp")
	defer os.Remove(tmp.Name())

	log.SetOutput(tmp)
	defer log.SetOutput(os.Stdout)

	cmd, _ := NewCommand("./testdata/test.sh failStuff --debug", "100ms")
	fields := log.Fields{"process": "test"}
	if err := RunWithTimeout(cmd, fields); err == nil {
		t.Errorf("Expected error but got nil")
	}
	time.Sleep(200 * time.Millisecond)

	buf, _ := ioutil.ReadFile(tmp.Name())
	logs := string(buf)

	if strings.Contains(logs, "timeout after") {
		t.Fatalf("RunWithTimeout failed to cancel timeout after failure: %v", logs)
	}
}
开发者ID:joyent,项目名称:containerpilot,代码行数:25,代码来源:commands_test.go


示例12: SetLoggingLevel

func SetLoggingLevel(debug bool) {
	if debug {
		log.SetLevel(log.DebugLevel)
	} else {
		log.SetLevel(log.InfoLevel)
	}
}
开发者ID:rancher,项目名称:catalog-dockerfiles,代码行数:7,代码来源:wrapper.go


示例13: setDebugMode

func setDebugMode(debug bool) {
	if !debug {
		logrus.SetLevel(logrus.InfoLevel)
	} else {
		logrus.SetLevel(logrus.DebugLevel)
	}
}
开发者ID:pombredanne,项目名称:oct,代码行数:7,代码来源:main.go


示例14: main

func main() {

	// configure logging
	logrus.SetLevel(logrus.InfoLevel)
	logrus.SetFormatter(&logrus.TextFormatter{FullTimestamp: true})

	// options to change log level
	globalOptions.Quiet = func() {
		logrus.SetLevel(logrus.WarnLevel)
	}
	globalOptions.Verbose = func() {
		logrus.SetLevel(logrus.DebugLevel)
	}
	globalOptions.LogJSON = func() {
		logrus.SetFormatter(&logrus.JSONFormatter{})
	}
	globalOptions.LogSyslog = func() {
		setupSyslog()
	}

	originalArgs = os.Args
	if _, err := parser.Parse(); err != nil {
		os.Exit(1)
	}
}
开发者ID:justone,项目名称:pmb,代码行数:25,代码来源:main.go


示例15: initConfig

// initConfig reads in config file and ENV variables if set.
func initConfig() {
	if len(cfgFile) != 0 {
		viper.SetConfigFile(cfgFile)
	}

	viper.SetConfigName(".otp-config")
	viper.AddConfigPath("$HOME")
	viper.AutomaticEnv()

	apiKey, _ := RootCmd.Flags().GetString("api-key")
	if len(apiKey) == 0 && len(os.Getenv("GITHUB_API_KEY")) > 0 {
		RootCmd.Flags().Set("api-key", os.Getenv("GITHUB_API_KEY"))
	}
	if len(apiKey) > 0 {
		if err := os.Setenv("GITHUB_API_KEY", apiKey); err != nil {
			fmt.Fprintf(os.Stderr, "Error: Unable to set GITHUB_API_KEY\n")
			os.Exit(1)
		}
	}

	// If a config file is found, read it in.
	if err := viper.ReadInConfig(); err == nil {
		fmt.Println("Using config file:", viper.ConfigFileUsed())
	}

	log.SetFormatter(&log.TextFormatter{})
	log.SetOutput(os.Stderr)
	if api.Verbose {
		log.SetLevel(log.DebugLevel)
	} else {
		log.SetLevel(log.WarnLevel)
	}
}
开发者ID:mfojtik,项目名称:dev-tools,代码行数:34,代码来源:root.go


示例16: setLogLevel

func (t *tether) setLogLevel() {
	// TODO: move all of this into an extension.Pre() block when we move to that model
	// adjust the logging level appropriately
	switch t.config.DebugLevel {
	case 0:
		log.SetLevel(log.InfoLevel)
		// TODO: do not echo application output to console without debug enabled
		serial.DisableTracing()
	case 1:
		log.SetLevel(log.DebugLevel)
		serial.DisableTracing()
	case 2:
		log.SetLevel(log.DebugLevel)
		serial.EnableTracing()

		log.Info("Launching pprof server on port 6060")
		fn := func() {
			go http.ListenAndServe("0.0.0.0:6060", nil)
		}

		once.Do(fn)
	default:
		log.SetLevel(log.DebugLevel)
		logConfig(t.config)
	}
}
开发者ID:vmware,项目名称:vic,代码行数:26,代码来源:tether.go


示例17: main

func main() {
	envflag.Parse()

	if *debug {
		logrus.SetLevel(logrus.DebugLevel)
	} else {
		logrus.SetLevel(logrus.WarnLevel)
	}

	handler := router.Load(
		ginrus.Ginrus(logrus.StandardLogger(), time.RFC3339, true),
		middleware.Version,
		middleware.Store(),
		middleware.Remote(),
		middleware.Cache(),
	)

	if *cert != "" {
		logrus.Fatal(
			http.ListenAndServeTLS(*addr, *cert, *key, handler),
		)
	} else {
		logrus.Fatal(
			http.ListenAndServe(*addr, handler),
		)
	}
}
开发者ID:jonbodner,项目名称:lgtm,代码行数:27,代码来源:main.go


示例18: LoadSettingsFromFile

func LoadSettingsFromFile() {
	viper.SetConfigType(ConfigType)
	setConfigLocation()

	// Set defaults
	viper.SetDefault("Port", Port)
	viper.SetDefault("EnableAutomerge", EnableAutomerge)
	viper.SetDefault("Debug", Debug)
	viper.SetDefault("DefaultEnvironment", DefaultEnvironment)
	viper.SetDefault("DefaultTask", DefaultTask)
	viper.SetDefault("BoltdbName", BoltdbName)

	// Load configuration
	err := viper.ReadInConfig()
	if err != nil {
		log.Warning("Configuration not found, loading defaults")
	}

	// set log level
	if viper.GetBool("Debug") {
		log.SetLevel(log.DebugLevel)
	} else {
		log.SetLevel(log.InfoLevel)
	}

	log.Debugf("Loaded setting values: %v", viper.AllSettings())
	log.Info("Settings loaded")
}
开发者ID:slok,项目名称:daton,代码行数:28,代码来源:load.go


示例19: init

func init() {
	cmf, err := os.Open("casemanager.conf")
	if err != nil {
		logrus.Fatal(err)
		return
	}
	defer cmf.Close()

	if err = json.NewDecoder(cmf).Decode(&pubConfig); err != nil {
		logrus.Fatal(err)
		return
	}

	if pubConfig.Debug {
		logrus.SetLevel(logrus.DebugLevel)
	} else {
		logrus.SetLevel(logrus.WarnLevel)
	}

	db := liboct.GetDefaultDB()
	db.RegistCollect(liboct.DBCase)
	db.RegistCollect(liboct.DBRepo)
	db.RegistCollect(liboct.DBTask)

	repos := pubConfig.Repos
	for index := 0; index < len(repos); index++ {
		if err := repos[index].IsValid(); err != nil {
			logrus.Warnf("The repo ", repos[index], " is invalid. ", err.Error())
			continue
		}
		if id, err := db.Add(liboct.DBRepo, repos[index]); err == nil {
			RefreshRepo(id)
		}
	}
}
开发者ID:pombredanne,项目名称:oct-engine,代码行数:35,代码来源:main.go


示例20: main

func main() {
	// let the user enter the number of points to be used
	numPoints := flag.Int("points", 1000, "Number of points to be generated")
	filename := flag.String("output", "curve", "name of the file where the image will be written")
	size := flag.Int("size", 1024, "Size of the file to be generated")
	debug := flag.Bool("d", false, "Print debug information")
	flag.Parse()

	if *debug {
		log.SetLevel(log.DebugLevel)
		log.Debug("Debug enabled")
	} else {
		log.SetLevel(log.InfoLevel)
	}

	runtime.GOMAXPROCS(runtime.NumCPU())
	file := fmt.Sprintf("%s.png", *filename)
	log.Info("Starting program")
	pl := point.RandomSlice(*numPoints)
	log.Info("Calculating matrix")
	m := matrix.FindSmallerCellSize(&pl)
	//fmt.Println("Initial matrix: ", m)
	canvas := drawing.NewCanvas(*size, file)
	strat := strategy.NewSnake(len(m.Squares))
	m.Draw(canvas, *strat)
	log.Info("Saving the image (this process might take a few minutes)")
	canvas.Save()
	log.Info("Finished program")
}
开发者ID:Willyfrog,项目名称:peano,代码行数:29,代码来源:main.go



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Golang logrus.SetOutput函数代码示例发布时间:2022-05-28
下一篇:
Golang logrus.SetFormatter函数代码示例发布时间: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