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


Golang logrus.SetLevel函数代码示例

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


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


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