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


Golang logrus.GetLevel函数代码示例

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


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

示例1: TestLoadDaemonCliConfigWithLogLevel

func TestLoadDaemonCliConfigWithLogLevel(t *testing.T) {
	c := &daemon.Config{}
	common := &cli.CommonFlags{}

	f, err := ioutil.TempFile("", "docker-config-")
	if err != nil {
		t.Fatal(err)
	}

	configFile := f.Name()
	f.Write([]byte(`{"log-level": "warn"}`))
	f.Close()

	flags := mflag.NewFlagSet("test", mflag.ContinueOnError)
	flags.String([]string{"-log-level"}, "", "")
	loadedConfig, err := loadDaemonCliConfig(c, flags, common, configFile)
	if err != nil {
		t.Fatal(err)
	}
	if loadedConfig == nil {
		t.Fatalf("expected configuration %v, got nil", c)
	}
	if loadedConfig.LogLevel != "warn" {
		t.Fatalf("expected warn log level, got %v", loadedConfig.LogLevel)
	}

	if logrus.GetLevel() != logrus.WarnLevel {
		t.Fatalf("expected warn log level, got %v", logrus.GetLevel())
	}
}
开发者ID:supasate,项目名称:docker,代码行数:30,代码来源:daemon_test.go

示例2: ReadBinary

// ReadBinary reads bytes into a Report.
//
// Will decompress the binary if gzipped is true, and will use the given
// codecHandle to decode it.
func (rep *Report) ReadBinary(r io.Reader, gzipped bool, codecHandle codec.Handle) error {
	var err error
	var compressedSize, uncompressedSize uint64

	// We have historically had trouble with reports being too large. We are
	// keeping this instrumentation around to help us implement
	// weaveworks/scope#985.
	if log.GetLevel() == log.DebugLevel {
		r = byteCounter{next: r, count: &compressedSize}
	}
	if gzipped {
		r, err = gzip.NewReader(r)
		if err != nil {
			return err
		}
	}
	if log.GetLevel() == log.DebugLevel {
		r = byteCounter{next: r, count: &uncompressedSize}
	}
	if err := codec.NewDecoder(r, codecHandle).Decode(&rep); err != nil {
		return err
	}
	log.Debugf(
		"Received report sizes: compressed %d bytes, uncompressed %d bytes (%.2f%%)",
		compressedSize,
		uncompressedSize,
		float32(compressedSize)/float32(uncompressedSize)*100,
	)
	return nil
}
开发者ID:CNDonny,项目名称:scope,代码行数:34,代码来源:marshal.go

示例3: TestDisableDebug

func TestDisableDebug(t *testing.T) {
	DisableDebug()
	if os.Getenv("DEBUG") != "" {
		t.Fatalf("expected DEBUG=\"\", got %s\n", os.Getenv("DEBUG"))
	}
	if logrus.GetLevel() != logrus.InfoLevel {
		t.Fatalf("expected log level %v, got %v\n", logrus.InfoLevel, logrus.GetLevel())
	}
}
开发者ID:CadeLaRen,项目名称:docker-3,代码行数:9,代码来源:debug_test.go

示例4: TestDebugMode

func (s *ConfigTestSuite) TestDebugMode(c *C) {
	type AnonConfig struct {
		Debug bool `json:"Debug"`
	}
	utils.WriteJsonFile(AnonConfig{Debug: true}, s.configPath)
	LoadSettingsFromFile()
	c.Assert(log.GetLevel(), Equals, log.DebugLevel)

	utils.WriteJsonFile(AnonConfig{Debug: false}, s.configPath)
	// Not need to reset because the conf file exists and loading it will overwrite
	LoadSettingsFromFile()
	c.Assert(log.GetLevel(), Equals, log.InfoLevel)
}
开发者ID:slok,项目名称:daton,代码行数:13,代码来源:load_test.go

示例5: TestClientDebugEnabled

func TestClientDebugEnabled(t *testing.T) {
	defer utils.DisableDebug()

	clientFlags.Common.FlagSet.Parse([]string{"-D"})
	clientFlags.PostParse()

	if os.Getenv("DEBUG") != "1" {
		t.Fatal("expected debug enabled, got false")
	}
	if logrus.GetLevel() != logrus.DebugLevel {
		t.Fatalf("expected logrus debug level, got %v", logrus.GetLevel())
	}
}
开发者ID:CrocdileChan,项目名称:docker,代码行数:13,代码来源:docker_test.go

示例6: TestEnableDebug

func TestEnableDebug(t *testing.T) {
	defer func() {
		os.Setenv("DEBUG", "")
		logrus.SetLevel(logrus.InfoLevel)
	}()
	EnableDebug()
	if os.Getenv("DEBUG") != "1" {
		t.Fatalf("expected DEBUG=1, got %s\n", os.Getenv("DEBUG"))
	}
	if logrus.GetLevel() != logrus.DebugLevel {
		t.Fatalf("expected log level %v, got %v\n", logrus.DebugLevel, logrus.GetLevel())
	}
}
开发者ID:CadeLaRen,项目名称:docker-3,代码行数:13,代码来源:debug_test.go

示例7: rquloop

func (n *node) rquloop() {
	for {
		time.Sleep(rqudelay)
		now := time.Now()
		n.pqs.mux.RLock()
		for k, v := range n.pqs.queues {
			v.L.Lock()
			_, exist := v.queue[v.waitingSeqid]
			if v.maxseqid > v.waitingSeqid && !exist && v.waitTime.Before(now.Add(-rqudelay)) {
				senderid, connid := unpacketKey(k)
				waiting := v.waitingSeqid
				v.waitTime = now.Add(rqudelay)
				go func() {
					n.write(&packet{
						Senderid: senderid,
						Connid:   connid,
						Seqid:    waiting,
						Cmd:      rqu,
						Time:     now.UnixNano(),
					})
					if logrus.GetLevel() >= logrus.DebugLevel {
						logrus.WithFields(logrus.Fields{
							"Connid":       connid,
							"StillWaiting": waiting,
							"role":         n.role(),
						}).Debugln("send packet request")
					}
				}()
			}
			v.L.Unlock()
		}
		n.pqs.mux.RUnlock()
	}
}
开发者ID:tomasen,项目名称:trafcacc,代码行数:34,代码来源:node.go

示例8: findContainers

func (c *Command) findContainers(client *docker.Client) ([]docker.APIContainers, error) {
	results, err := client.ListContainers(docker.ListContainersOptions{})
	if err != nil {
		return nil, err
	}

	stopped := make([]docker.APIContainers, 0)
	for _, container := range results {
		if log.GetLevel() >= log.DebugLevel {
			b, err := json.Marshal(&container)
			if err == nil {
				log.Debugln("check container: ", string(b))
			}
		}

		if c.Name != "" && !strings.HasPrefix(container.ID, c.Name) {
			continue
		} else if c.Image != "" && container.Image != c.Image {
			continue
		}
		log.WithFields(log.Fields{
			"id": container.ID,
		}).Debugln("find target container.")

		stopped = append(stopped, container)
	}
	return stopped, nil
}
开发者ID:jmptrader,项目名称:beacon,代码行数:28,代码来源:command.go

示例9: EnvmanRun

// EnvmanRun ...
func EnvmanRun(envstorePth, workDirPth string, cmd []string) (int, error) {
	logLevel := log.GetLevel().String()
	args := []string{"--loglevel", logLevel, "--path", envstorePth, "run"}
	args = append(args, cmd...)

	return cmdex.RunCommandInDirAndReturnExitCode(workDirPth, "envman", args...)
}
开发者ID:andrewhavens,项目名称:bitrise,代码行数:8,代码来源:run.go

示例10: TestWithLevel

// TestWithLevel run callable with changed logging output and log level
func TestWithLevel(level string, callable func(*bytes.Buffer)) {
	originalLevel := logrus.GetLevel()
	defer logrus.SetLevel(originalLevel)
	SetLevel(level)

	Test(callable)
}
开发者ID:xyntrix,项目名称:go-carbon,代码行数:8,代码来源:logger.go

示例11: listen

func (s *serv) listen() {
	switch s.proto {
	case tcp:
		ln, err := net.Listen("tcp", s.addr)
		if err != nil {
			logrus.Fatalln("net.Listen error", s.addr, err)
		}

		s.setalive()

		if logrus.GetLevel() >= logrus.DebugLevel {
			logrus.Debugln("listen to", s.addr)
		}
		go acceptTCP(ln, s.tcphandler)
	case udp:
		udpaddr, err := net.ResolveUDPAddr("udp", s.addr)
		if err != nil {
			logrus.Fatalln("net.ResolveUDPAddr error", s.addr, err)
		}
		udpconn, err := net.ListenUDP("udp", udpaddr)
		if err != nil {
			logrus.Fatalln("net.ListenUDP error", udpaddr, err)
		}

		s.setalive()

		go func() {
			for {
				s.udphandler(udpconn)
			}
		}()
	}
}
开发者ID:tomasen,项目名称:trafcacc,代码行数:33,代码来源:server.go

示例12: runCharon

func runCharon(logFile string) {
	// Ignore error
	os.Remove("/var/run/charon.vici")

	args := []string{}
	for _, i := range strings.Split("dmn|mgr|ike|chd|cfg|knl|net|asn|tnc|imc|imv|pts|tls|esp|lib", "|") {
		args = append(args, "--debug-"+i)
		if logrus.GetLevel() == logrus.DebugLevel {
			args = append(args, "3")
		} else {
			args = append(args, "1")
		}
	}

	cmd := exec.Command("charon", args...)
	cmd.Stdout = os.Stdout
	cmd.Stderr = os.Stderr

	if logFile != "" {
		output, err := os.OpenFile(logFile, os.O_RDWR|os.O_CREATE|os.O_APPEND, 0666)
		if err != nil {
			logrus.Fatalf("Failed to log to file %s: %v", logFile, err)
		}
		defer output.Close()
		cmd.Stdout = output
		cmd.Stderr = output
	}

	cmd.SysProcAttr = &syscall.SysProcAttr{
		Pdeathsig: syscall.SIGTERM,
	}

	logrus.Fatalf("charon exited: %v", cmd.Run())
}
开发者ID:ibuildthecloud,项目名称:rancher-net,代码行数:34,代码来源:ipsec.go

示例13: ExecuteWithOutput

// ExecuteWithOutput executes a command. If logrus's verbosity level is set to
// debug, it will continuously output the command's output while it waits.
func ExecuteWithOutput(cmd *exec.Cmd) (outStr string, err error) {
	// connect to stdout and stderr for filtering purposes
	errPipe, err := cmd.StderrPipe()
	if err != nil {
		log.WithFields(log.Fields{
			"cmd": cmd.Args,
		}).Fatal("Couldn't connect to command's stderr")
	}
	outPipe, err := cmd.StdoutPipe()
	if err != nil {
		log.WithFields(log.Fields{
			"cmd": cmd.Args,
		}).Fatal("Couldn't connect to command's stdout")
	}
	_ = bufio.NewReader(errPipe)
	outReader := bufio.NewReader(outPipe)

	// start the command and filter the output
	if err = cmd.Start(); err != nil {
		return "", err
	}
	outScanner := bufio.NewScanner(outReader)
	for outScanner.Scan() {
		outStr += outScanner.Text() + "\n"
		if log.GetLevel() == log.DebugLevel {
			fmt.Println(outScanner.Text())
		}
	}
	err = cmd.Wait()
	return outStr, err
}
开发者ID:lokinell,项目名称:microservices-infrastructure,代码行数:33,代码来源:mi-deploy.go

示例14: SendMessage

func (server *Server) SendMessage(ctx context.Context, in *pb.Message) (*pb.SendMessageResponse, error) {
	if in.Language == "" {
		in.Language = server.Config.DefaultLanguage
	}
	n := len(in.Targets)
	logrus.Debugf("SendMessage with event='%s' and language='%s' to #%d target(s)", in.Event, in.Language, n)
	results := make([]*pb.MessageTargetResponse, 0)
	ch := make(chan drivers.DriverResult, 1)
	go server.send(ctx, in, ch)

	for i := 0; i < n; i++ {
		r := <-ch
		resp := &pb.MessageTargetResponse{
			Target: string(r.Type),
			Output: "Success",
		}
		if r.Err != nil {
			resp.Output = r.Err.Error()
		}
		results = append(results, resp)
	}
	if logrus.GetLevel() >= logrus.DebugLevel {
		for _, t := range results {
			logrus.Debugf("SendMessage output[%s]= %s", t.Target, t.Output)
		}
	}
	return pb.NewMessageResponse(results), nil
}
开发者ID:otsimo,项目名称:simple-notifications,代码行数:28,代码来源:service.go

示例15: ServeHTTP

func (s *CacheHandler) ServeHTTP(w http.ResponseWriter, req *http.Request) {
	var uid string

	if session, ok := SessionFromContext(req.Context()); ok {
		uid = session.Token.UidString()
	} else {
		sendRequestProblem(w, req, http.StatusBadRequest, errors.New("CacheHandler no UID"))
		return
	}

	if req.Method == "GET" && infoCollectionsRoute.MatchString(req.URL.Path) { // info/collections
		s.infoCollection(uid, w, req)
	} else if req.Method == "GET" && infoConfigurationRoute.MatchString(req.URL.Path) { // info/configuration
		s.infoConfiguration(uid, w, req)
	} else {
		// clear the cache for the  user
		if req.Method == "POST" || req.Method == "PUT" || req.Method == "DELETE" {
			if log.GetLevel() == log.DebugLevel {
				log.WithFields(log.Fields{
					"uid": uid,
				}).Debug("CacheHandler clear")
			}
			s.cache.Set(uid, nil)
		}
		s.handler.ServeHTTP(w, req)
		return
	}
}
开发者ID:mozilla-services,项目名称:go-syncstorage,代码行数:28,代码来源:cacheHandler.go


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