本文整理汇总了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())
}
}
示例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
}
示例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())
}
}
示例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)
}
示例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())
}
}
示例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())
}
}
示例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()
}
}
示例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
}
示例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...)
}
示例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)
}
示例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)
}
}()
}
}
示例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())
}
示例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
}
示例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
}
示例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
}
}