當前位置: 首頁>>代碼示例>>Golang>>正文


Golang logrus.Warningf函數代碼示例

本文整理匯總了Golang中github.com/Sirupsen/logrus.Warningf函數的典型用法代碼示例。如果您正苦於以下問題:Golang Warningf函數的具體用法?Golang Warningf怎麽用?Golang Warningf使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了Warningf函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: SinkFactory

// SinkFactory creates a new object with sinks.Sink interface
func SinkFactory() sinks.Sink {
	sinkType := viper.GetString("sink-type")
	filename := viper.GetString("filesystem-filename")
	maxAge := viper.GetInt("filesystem-max-age")
	maxBackups := viper.GetInt("filesystem-max-backups")
	maxSize := viper.GetInt("filesystem-max-size")

	if sinkType == "filesystem" {
		return sinks.NewFilesystemSink(filename, maxAge, maxBackups, maxSize)
	}

	output := viper.GetString("console-output")
	var stdOutput *os.File

	if sinkType == "console" {
		if output == "stdout" {
			stdOutput = os.Stdout
		} else if output == "stderr" {
			stdOutput = os.Stderr
		} else {
			log.Warningf("Unknown console output type '%s'. Falling back to 'stdout'", output)
		}
		return sinks.NewConsoleSink(stdOutput)
	}

	log.Warningf("Unknown sink type '%s'. Falling back to 'filesystem'", sinkType)
	return sinks.NewFilesystemSink(filename, maxAge, maxBackups, maxSize)
}
開發者ID:admiralobvious,項目名稱:tinysyslog,代碼行數:29,代碼來源:factories.go

示例2: sendToHTTP

func sendToHTTP(pmbConn *Connection, done chan error, id string) {
	logrus.Debugf("Sending to URI %s.", pmbConn.uri)
	done <- nil
	for {
		message := <-pmbConn.Out

		bodies, err := prepareMessage(message, pmbConn.Keys, id)
		if err != nil {
			logrus.Warningf("Error preparing message: %s", err)
			continue
		}

		for _, body := range bodies {
			logrus.Debugf("Sending raw message: %s", string(body))
			_, err := http.Post(pmbConn.uri, "application/json", bytes.NewReader(body))
			if err != nil {
				logrus.Warningf("Error sending: %s", err)
			}
		}

		if message.Done != nil {
			logrus.Debugf("Done channel present, sending message")
			message.Done <- nil
		}
	}
}
開發者ID:justone,項目名稱:pmb,代碼行數:26,代碼來源:http.go

示例3: Watch

// Watches for new vms, or vms destroyed.
func (self *Container) Watch(eventsChannel *EventChannel) error {
	self.stop = make(chan struct{})
	go func() {
		for {
			select {
			case event := <-eventsChannel.channel:
				switch {
				case event.EventAction == alerts.LAUNCHED:
					err := self.create()
					if err != nil {
						log.Warningf("Failed to process watch event: %v", err)
					}
				case event.EventAction == alerts.DESTROYED:
					err := self.destroy()
					if err != nil {
						log.Warningf("Failed to process watch event: %v", err)
					}
				}
			case <-self.stop:
				log.Info("container watcher exiting")
				return
			}
		}
	}()
	return nil
}
開發者ID:vijaykanthm28,項目名稱:libgo,代碼行數:27,代碼來源:container.go

示例4: listenToHTTP

func listenToHTTP(pmbConn *Connection, done chan error, id string) {
	listenURI := fmt.Sprintf("%s/%s", pmbConn.uri, id)
	logrus.Debugf("Listening on URI %s.", listenURI)
	done <- nil
	for {
		res, err := http.Get(listenURI)
		if err != nil {
			logrus.Warningf("Error receiving: %s", err)
			time.Sleep(1 * time.Second)
			continue
		}

		body, err := ioutil.ReadAll(res.Body)
		res.Body.Close()
		if err != nil {
			logrus.Warningf("Error reading body: %s", err)
			time.Sleep(1 * time.Second)
			continue
		}

		if res.StatusCode == 200 {
			parseMessage(body, pmbConn.Keys, pmbConn.In, id)
		} else if res.StatusCode == 408 {
			continue
		} else {
			logrus.Warningf("Bad request: %s", res.Status)
			time.Sleep(1 * time.Second)
		}
	}
}
開發者ID:justone,項目名稱:pmb,代碼行數:30,代碼來源:http.go

示例5: bundleContainerLogs

func (s *server) bundleContainerLogs(res http.ResponseWriter, req *http.Request, f format) {
	defer trace.End(trace.Begin(""))

	readers := defaultReaders
	c, err := s.getSessionFromRequest(req)
	if err != nil {
		log.Errorf("Failed to get vSphere session while bundling container logs due to error: %s", err.Error())
		http.Error(res, genericErrorMessage, http.StatusInternalServerError)
		return
	}

	// Note: we don't want to Logout() until tarEntries() completes below
	defer c.Client.Logout(context.Background())

	logs, err := findDatastoreLogs(c)
	if err != nil {
		log.Warningf("error searching datastore: %s", err)
	} else {
		for key, rdr := range logs {
			readers[key] = rdr
		}
	}

	logs, err = findDiagnosticLogs(c)
	if err != nil {
		log.Warningf("error collecting diagnostic logs: %s", err)
	} else {
		for key, rdr := range logs {
			readers[key] = rdr
		}
	}

	s.bundleLogs(res, req, readers, f)
}
開發者ID:vmware,項目名稱:vic,代碼行數:34,代碼來源:server.go

示例6: SendMessage

func (server *Server) SendMessage(ctx context.Context, in *pb.Message) (*pb.SendMessageResponse, error) {
	log.Infof("server.go: SendMessage with template='%s' and language='%s' to #%d target(s)", in.Template, in.Language, len(in.Targets))

	temp := server.GetTemplateGroup(in.Template)
	results := make([]*pb.MessageTargetResponse, 0)

	if temp == nil {
		return pb.NewCustomMessageResponse(pb.ResultTemplateGroupNotFound,
			fmt.Sprintf("template=%s not found", in.Template), results), nil
	}

	for _, t := range in.Targets {
		ty := getTargetType(t)
		if len(ty) > 0 {
			driver := server.Drivers[ty]
			if driver != nil {
				err := driver.Send(in.Language, server.Config.DefaultLanguage, t, temp)
				if err != nil {
					results = append(results, &pb.MessageTargetResponse{Type: pb.ResultInternalDriverError, Data: fmt.Sprint(err)})
				} else {
					results = append(results, pb.NewMessageTargetResponse(pb.ResultSuccess, driver.Type(), driver.Name()))
				}
			} else {
				log.Warningf("server.go: %s driver not found", ty)
				results = append(results, pb.NewMessageTargetResponse(pb.ResultDriverNotFound, ty, ""))
			}
		} else {
			log.Warningf("server.go: there is no suitable driver")
			results = append(results, pb.NewMessageTargetResponse(pb.ResultDriverNotFound, "", ""))
		}
	}
	return pb.NewMessageResponse(pb.ResultSuccess, results), nil
}
開發者ID:mehulsbhatt,項目名稱:simple-notifications,代碼行數:33,代碼來源:server.go

示例7: dialFactory

func (d *Dialer) dialFactory(network, address string) (net.Conn, error) {
	tcpAddr, err := d.aPool.GetRoundRobin()
	if err != nil {
		logrus.Warningf("aPool.GetRoundRobin error", err)
		return d.Dialer.Dial(network, address)
	}
	c, err := net.DialTCP(network, nil, tcpAddr)
	if err != nil {
		logrus.Warningf("Failed to setup DialTCP: %s, fallback dialer.Dial", err)
		return d.Dialer.Dial(network, address)
	}
	if d.KeepAlive != 0 {
		if err = c.SetKeepAlive(true); err != nil {
			return nil, err
		}
		if err = c.SetKeepAlivePeriod(d.KeepAlive); err != nil {
			return nil, err
		}
		if err = c.SetLinger(0); err != nil {
			return nil, err
		}
		if err = c.SetNoDelay(true); err != nil {
			return nil, err
		}
	}
	return c, err
}
開發者ID:linkosmos,項目名稱:redial,代碼行數:27,代碼來源:redial.go

示例8: bundleContainerLogs

func (s *server) bundleContainerLogs(res http.ResponseWriter, req *http.Request, f format) {
	defer trace.End(trace.Begin(""))

	readers := defaultReaders

	if config.Service != "" {
		c, err := client()
		if err != nil {
			log.Errorf("failed to connect: %s", err)
		} else {
			// Note: we don't want to Logout() until tarEntries() completes below
			defer c.Client.Logout(context.Background())

			logs, err := findDatastoreLogs(c)
			if err != nil {
				log.Warningf("error searching datastore: %s", err)
			} else {
				for key, rdr := range logs {
					readers[key] = rdr
				}
			}

			logs, err = findDiagnosticLogs(c)
			if err != nil {
				log.Warningf("error collecting diagnostic logs: %s", err)
			} else {
				for key, rdr := range logs {
					readers[key] = rdr
				}
			}
		}
	}

	s.bundleLogs(res, req, readers, f)
}
開發者ID:kjplatz,項目名稱:vic,代碼行數:35,代碼來源:server.go

示例9: processPaths

func (c *fileArchiver) processPaths() {
	for _, path := range c.Paths {
		matches, err := filepath.Glob(path)
		if err != nil {
			logrus.Warningf("%s: %v", path, err)
			continue
		}

		found := 0

		for _, match := range matches {
			err := filepath.Walk(match, func(path string, info os.FileInfo, err error) error {
				if c.process(path) {
					found++
				}
				return nil
			})
			if err != nil {
				logrus.Warningln("Walking", match, err)
			}
		}

		if found == 0 {
			logrus.Warningf("%s: no matching files", path)
		} else {
			logrus.Infof("%s: found %d matching files", path, found)
		}
	}
}
開發者ID:bssthu,項目名稱:gitlab-ci-multi-runner,代碼行數:29,代碼來源:file_archiver.go

示例10: report

func (p *Probe) report() report.Report {
	reports := make(chan report.Report, len(p.reporters))
	for _, rep := range p.reporters {
		go func(rep Reporter) {
			t := time.Now()
			timer := time.AfterFunc(p.spyInterval, func() { log.Warningf("%v reporter took longer than %v", rep.Name(), p.spyInterval) })
			newReport, err := rep.Report()
			if !timer.Stop() {
				log.Warningf("%v reporter took %v (longer than %v)", rep.Name(), time.Now().Sub(t), p.spyInterval)
			}
			metrics.MeasureSince([]string{rep.Name(), "reporter"}, t)
			if err != nil {
				log.Errorf("error generating report: %v", err)
				newReport = report.MakeReport() // empty is OK to merge
			}
			reports <- newReport
		}(rep)
	}

	result := report.MakeReport()
	for i := 0; i < cap(reports); i++ {
		result = result.Merge(<-reports)
	}
	return result
}
開發者ID:CNDonny,項目名稱:scope,代碼行數:25,代碼來源:probe.go

示例11: loopServerConn

func (lay *Layer) loopServerConn(prot *protocol.Protocol) bool {
	// Check if we need to quit:
	select {
	case <-lay.childCtx.Done():
		return false
	default:
		break
	}

	req := wire.Request{}
	if err := prot.Recv(&req); err != nil {
		if err != io.EOF {
			log.Warningf("Server side recv: %v", err)
		}

		return false
	}

	log.Debugf("Got request: %v", req)
	fn, ok := lay.handlers[req.ReqType]
	if !ok {
		log.Warningf("Received packet without registerd handler (%d)", req.ReqType)
		log.Warningf("Package will be dropped.")
		return true
	}

	resp, err := fn(&req)
	if err != nil {
		resp = &wire.Response{
			Error: err.Error(),
		}
	}

	if resp == nil {
		// '0' is the ID for broadcast. Empty response are valid there.
		if req.ID != 0 {
			log.Warningf("Handle for `%d` failed to return a response or error", req.ReqType)
		}

		return true
	}

	// Auto-fill the type and ID fields from the response:
	resp.ReqType = req.ReqType
	resp.ID = req.ID
	resp.Nonce = req.Nonce

	log.Debugf("Sending back %v", resp)
	if err := prot.Send(resp); err != nil {
		log.Warningf("Unable to send back response: %v", err)
		return false
	}

	return true
}
開發者ID:disorganizer,項目名稱:brig,代碼行數:55,代碼來源:moose.go

示例12: loadConfig

func loadConfig() *config.Config {
	// We do not use guessRepoFolder() here. It might abort
	folder := repo.GuessFolder()
	cfg, err := repoconfig.LoadConfig(filepath.Join(folder, ".brig", "config"))
	if err != nil {
		log.Warningf("Could not load config: %v", err)
		log.Warningf("Falling back on config defaults...")
		return repoconfig.CreateDefaultConfig()
	}

	return cfg
}
開發者ID:disorganizer,項目名稱:brig,代碼行數:12,代碼來源:handleutil.go

示例13: newTLSConfig

func (s *srv) newTLSConfig() (*tls.Config, error) {
	config, err := s.listener.TLSConfig()
	if err != nil {
		return nil, err
	}

	if config.NextProtos == nil {
		config.NextProtos = []string{"http/1.1"}
	}

	pairs := map[string]tls.Certificate{}
	for _, host := range s.mux.hosts {
		c := host.Settings.KeyPair
		if c == nil {
			continue
		}
		keyPair, err := tls.X509KeyPair(c.Cert, c.Key)
		if err != nil {
			return nil, err
		}
		if host.Settings.OCSP.Enabled {
			log.Infof("%v OCSP is enabled for %v, resolvers: %v", s, host, host.Settings.OCSP.Responders)
			r, err := s.mux.stapler.StapleHost(&host)
			if err != nil {
				log.Warningf("%v failed to staple %v, error %v", s, host, err)
			} else if r.Response.Status == ocsp.Good || r.Response.Status == ocsp.Revoked {
				keyPair.OCSPStaple = r.Staple
			} else {
				log.Warningf("%s got undefined status from OCSP responder: %v", s, r.Response.Status)
			}
		}
		pairs[host.Name] = keyPair
	}

	config.Certificates = make([]tls.Certificate, 0, len(pairs))
	if s.defaultHost != "" {
		keyPair, exists := pairs[s.defaultHost]
		if !exists {
			return nil, fmt.Errorf("default host '%s' certificate is not passed", s.defaultHost)
		}
		config.Certificates = append(config.Certificates, keyPair)
	}

	for h, keyPair := range pairs {
		if h != s.defaultHost {
			config.Certificates = append(config.Certificates, keyPair)
		}
	}

	config.BuildNameToCertificate()
	return config, nil
}
開發者ID:vulcand,項目名稱:vulcand,代碼行數:52,代碼來源:srv.go

示例14: handlePickle

func (rcv *TCP) handlePickle(conn net.Conn) {
	atomic.AddInt32(&rcv.active, 1)
	defer atomic.AddInt32(&rcv.active, -1)

	defer conn.Close()
	reader := bufio.NewReader(conn)

	var msgLen uint32
	var err error

	for {
		conn.SetReadDeadline(time.Now().Add(2 * time.Minute))

		// Read prepended length
		err = binary.Read(reader, binary.BigEndian, &msgLen)
		if err != nil {
			if err == io.EOF {
				return
			}

			atomic.AddUint32(&rcv.errors, 1)
			logrus.Warningf("[pickle] Can't read message length: %s", err.Error())
			return
		}

		// Allocate a byte array of the expected length
		data := make([]byte, msgLen)

		// Read remainder of pickle packet into byte array
		if err = binary.Read(reader, binary.BigEndian, data); err != nil {
			atomic.AddUint32(&rcv.errors, 1)
			logrus.Warningf("[pickle] Can't read message body: %s", err.Error())
			return
		}

		msgs, err := points.ParsePickle(data)

		if err != nil {
			atomic.AddUint32(&rcv.errors, 1)
			logrus.Infof("[pickle] Can't unpickle message: %s", err.Error())
			logrus.Debugf("[pickle] Bad message: %#v", string(data))
			return
		}

		for _, msg := range msgs {
			atomic.AddUint32(&rcv.metricsReceived, uint32(len(msg.Data)))
			rcv.out <- msg
		}
	}
}
開發者ID:EyckWigo,項目名稱:go-carbon,代碼行數:50,代碼來源:tcp.go

示例15: handleConnection

func (listener *CarbonlinkListener) handleConnection(conn net.Conn) {
	defer conn.Close()
	reader := bufio.NewReader(conn)

	for {
		conn.SetReadDeadline(time.Now().Add(listener.readTimeout))

		reqData, err := ReadCarbonlinkRequest(reader)
		if err != nil {
			logrus.Debugf("[carbonlink] read carbonlink request from %s: %s", conn.RemoteAddr().String(), err.Error())
			break
		}

		req, err := ParseCarbonlinkRequest(reqData)

		if err != nil {
			logrus.Warningf("[carbonlink] parse carbonlink request from %s: %s", conn.RemoteAddr().String(), err.Error())
			break
		}
		if req != nil {
			if req.Type != "cache-query" {
				logrus.Warningf("[carbonlink] unknown query type: %#v", req.Type)
				break
			}

			if req.Type == "cache-query" {
				cacheReq := NewQuery(req.Metric)
				listener.queryChan <- cacheReq

				var reply *Reply

				select {
				case reply = <-cacheReq.ReplyChan:
				case <-time.After(listener.queryTimeout):
					logrus.Infof("[carbonlink] Cache no reply (%s timeout)", listener.queryTimeout)
					reply = NewReply()
				}
				packed := listener.packReply(reply)
				if packed == nil {
					break
				}
				if _, err := conn.Write(packed); err != nil {
					logrus.Infof("[carbonlink] reply error: %s", err)
					break
				}
				// pp.Println(reply)
			}
		}
	}
}
開發者ID:EyckWigo,項目名稱:go-carbon,代碼行數:50,代碼來源:carbonlink.go


注:本文中的github.com/Sirupsen/logrus.Warningf函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。