本文整理汇总了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
}
示例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()
}
示例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)
}
示例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
}
示例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
}
示例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)
}
}
示例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()
}
示例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")
}
}
示例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
}
示例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
}
示例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)
}
}
示例12: SetLoggingLevel
func SetLoggingLevel(debug bool) {
if debug {
log.SetLevel(log.DebugLevel)
} else {
log.SetLevel(log.InfoLevel)
}
}
示例13: setDebugMode
func setDebugMode(debug bool) {
if !debug {
logrus.SetLevel(logrus.InfoLevel)
} else {
logrus.SetLevel(logrus.DebugLevel)
}
}
示例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)
}
}
示例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)
}
}