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


Golang logging.GetLogger函數代碼示例

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


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

示例1: FLowsFromSFlowSample

func FLowsFromSFlowSample(ft *FlowTable, sample *layers.SFlowFlowSample, probePath string) []*Flow {
	flows := []*Flow{}

	for _, rec := range sample.Records {

		/* FIX(safchain): just keeping the raw packet for now */
		switch rec.(type) {
		case layers.SFlowRawPacketFlowRecord:
			/* We only support RawPacket from SFlow probe */
		case layers.SFlowExtendedSwitchFlowRecord:
			logging.GetLogger().Debug("1st layer is not SFlowRawPacketFlowRecord type")
			continue
		default:
			logging.GetLogger().Critical("1st layer is not a SFlow supported type")
			continue
		}

		record := rec.(layers.SFlowRawPacketFlowRecord)

		packet := &record.Header
		key := (FlowKey{}).fillFromGoPacket(packet)
		flow, _ := ft.GetFlow(key.String())
		flow.ProbeGraphPath = probePath
		flow.fillFromGoPacket(packet)
		flows = append(flows, flow)
	}

	return flows
}
開發者ID:safchain,項目名稱:skydive,代碼行數:29,代碼來源:flow.go

示例2: connect

func (probe *DockerProbe) connect() error {
	var err error

	logging.GetLogger().Debugf("Connecting to Docker daemon: %s", probe.url)
	probe.client, err = dockerclient.NewDockerClient(probe.url, nil)
	if err != nil {
		logging.GetLogger().Errorf("Failed to connect to Docker daemon: %s", err.Error())
		return err
	}

	eventsOptions := &dockerclient.MonitorEventsOptions{
		Filters: &dockerclient.MonitorEventsFilters{
			Events: []string{"start", "die"},
		},
	}

	eventErrChan, err := probe.client.MonitorEvents(eventsOptions, nil)
	if err != nil {
		logging.GetLogger().Errorf("Unable to monitor Docker events: %s", err.Error())
		return err
	}

	probe.wg.Add(2)
	probe.quit = make(chan bool)

	probe.connected.Store(true)
	defer probe.connected.Store(false)

	go func() {
		defer probe.wg.Done()

		containers, err := probe.client.ListContainers(false, false, "")
		if err != nil {
			logging.GetLogger().Errorf("Failed to list containers: %s", err.Error())
			return
		}

		for _, c := range containers {
			if atomic.LoadInt64(&probe.state) != RunningState {
				break
			}
			probe.registerContainer(c.Id)
		}
	}()

	defer probe.wg.Done()

	for {
		select {
		case <-probe.quit:
			return nil
		case e := <-eventErrChan:
			if e.Error != nil {
				logging.GetLogger().Errorf("Got error while waiting for Docker event: %s", e.Error.Error())
				return e.Error
			}
			probe.handleDockerEvent(&e.Event)
		}
	}
}
開發者ID:lebauce,項目名稱:skydive,代碼行數:60,代碼來源:docker.go

示例3: SetMetadata

func (g GremlinBackend) SetMetadata(i interface{}, k string, v interface{}) bool {
	var e graphElement
	var elType string

	switch i.(type) {
	case *Node:
		e = i.(*Node).graphElement
		elType = "V"
	case *Edge:
		e = i.(*Edge).graphElement
		elType = "V"
	}

	properties, err := idToPropertiesString(e.ID)
	if err != nil {
		logging.GetLogger().Error("Error while retrieving a Node: %s", err.Error())
		return false
	}

	encoder := gremlin.GremlinPropertiesEncoder{}
	encoder.EncodeKVPair(k, v)

	query := "g." + elType + "().has(" + properties + ").property(" + encoder.String() + ")"

	_, err = g.client.Query(query)
	if err != nil {
		logging.GetLogger().Error("Gremlin query error: %s, %s", query, err.Error())
		return false
	}

	return true
}
開發者ID:mestery,項目名稱:skydive,代碼行數:32,代碼來源:gremlin.go

示例4: cacheUpdater

func (gfe *GraphFlowEnhancer) cacheUpdater() {
	logging.GetLogger().Debug("Start GraphFlowEnhancer cache updater")

	var mac string
	for {
		mac = <-gfe.cacheUpdaterChan

		logging.GetLogger().Debug("GraphFlowEnhancer request received: %s", mac)

		gfe.Graph.Lock()
		intfs := gfe.Graph.LookupNodes(graph.Metadatas{"MAC": mac})

		if len(intfs) > 1 {
			logging.GetLogger().Info("GraphFlowEnhancer found more than one interface for the mac: %s", mac)
			continue
		}

		if len(intfs) == 1 {
			ancestors, ok := gfe.Graph.GetAncestorsTo(intfs[0], graph.Metadatas{"Type": "host"})
			if ok {
				var path string
				for i := len(ancestors) - 1; i >= 0; i-- {
					if len(path) > 0 {
						path += "/"
					}
					name, _ := ancestors[i].Metadatas()["Name"]
					path += name.(string)
				}

				gfe.cache.Set(mac, path, cache.DefaultExpiration)
			}
		}
		gfe.Graph.Unlock()
	}
}
開發者ID:mestery,項目名稱:skydive,代碼行數:35,代碼來源:graph.go

示例5: startTopologyClient

func startTopologyClient(t *testing.T, g *graph.Graph, onReady func(*websocket.Conn), onChange func(*websocket.Conn)) error {
	// ready when got a first ping
	ws, err := connectToAgent(5, onReady)
	if err != nil {
		return err
	}

	for {
		_, m, err := ws.ReadMessage()
		if err != nil {
			break
		}

		err = processGraphMessage(g, m)
		if err != nil {
			return err
		}

		logging.GetLogger().Debug("%s", string(m))
		logging.GetLogger().Debug("%s", g.String())

		onChange(ws)
	}

	return nil
}
開發者ID:mestery,項目名稱:skydive,代碼行數:26,代碼來源:topology_test.go

示例6: AddEdge

func (g GremlinBackend) AddEdge(e *Edge) bool {
	properties, err := toPropertiesString(e.graphElement)
	if err != nil {
		logging.GetLogger().Error("Error while adding a new Edge: %s", err.Error())
		return false
	}

	propsParent, err := idToPropertiesString(e.parent)
	if err != nil {
		logging.GetLogger().Error("Error while adding a new Edge: %s", err.Error())
		return false
	}

	propsChild, err := idToPropertiesString(e.child)
	if err != nil {
		logging.GetLogger().Error("Error while adding a new Edge: %s", err.Error())
		return false
	}

	query := "g.V().has(" + propsParent + ").next()"
	query += ".addEdge('linked', g.V().has(" + propsChild + ").next(), " + string(properties) + ")"
	_, err = g.client.Query(query)
	if err != nil {
		logging.GetLogger().Error("Error while adding a new Node: %s", err.Error())
		return false
	}

	return true
}
開發者ID:mestery,項目名稱:skydive,代碼行數:29,代碼來源:gremlin.go

示例7: Connect

func (c *GremlinClient) Connect() {
	host := c.Addr + ":" + strconv.FormatInt(int64(c.Port), 10)

	conn, err := net.Dial("tcp", host)
	if err != nil {
		logging.GetLogger().Error("Connection to the WebSocket server failed: %s", err.Error())
		return
	}

	endpoint := "ws://" + host
	u, err := url.Parse(endpoint)
	if err != nil {
		logging.GetLogger().Error("Unable to parse the WebSocket Endpoint %s: %s", endpoint, err.Error())
		return
	}

	wsConn, _, err := websocket.NewClient(conn, u, http.Header{}, 0, 4096)
	if err != nil {
		logging.GetLogger().Error("Unable to create a WebSocket connection %s : %s", endpoint, err.Error())
		return
	}

	logging.GetLogger().Info("Connected to gremlin server %s:%d", c.Addr, c.Port)

	c.wsConn = wsConn
}
開發者ID:mestery,項目名稱:skydive,代碼行數:26,代碼來源:client.go

示例8: handleUDPFlowPacket

func (s *Server) handleUDPFlowPacket() {
	s.conn.SetDeadline(time.Now().Add(200 * time.Millisecond))
	data := make([]byte, 4096)

	for s.running.Load() == true {
		n, _, err := s.conn.ReadFromUDP(data)
		if err != nil {
			if err.(net.Error).Timeout() == true {
				s.conn.SetDeadline(time.Now().Add(200 * time.Millisecond))
				continue
			}
			if s.running.Load() == false {
				return
			}
			logging.GetLogger().Errorf("Error while reading: %s", err.Error())
			return
		}

		f, err := flow.FromData(data[0:n])
		if err != nil {
			logging.GetLogger().Errorf("Error while parsing flow: %s", err.Error())
		}

		s.AnalyzeFlows([]*flow.Flow{f})
	}
}
開發者ID:fdebonneval,項目名稱:skydive,代碼行數:26,代碼來源:server.go

示例9: GetEdge

func (g GremlinBackend) GetEdge(i Identifier) *Edge {
	properties, err := idToPropertiesString(i)
	if err != nil {
		logging.GetLogger().Error("Error while retrieving a Node: %s", err.Error())
		return nil
	}

	query := "g.E().has(" + properties + ")"

	els, err := g.client.QueryElements(query)
	if err != nil {
		return nil
	}

	switch l := len(els); {
	case l == 0:
		return nil
	case l > 1:
		logging.GetLogger().Error("Found more than one edge for this ID: " + string(i))
		return nil
	}

	edge := gremElementToEdge(els[0])

	parent, child := g.GetEdgeNodes(edge)
	if parent == nil || child == nil {
		return nil
	}

	edge.parent = parent.ID
	edge.child = child.ID

	return edge
}
開發者ID:mestery,項目名稱:skydive,代碼行數:34,代碼來源:gremlin.go

示例10: start

func (u *NetNSTopoUpdater) start() {
	runtime.LockOSThread()
	defer runtime.UnlockOSThread()

	watcher, err := inotify.NewWatcher()
	if err != nil {
		logging.GetLogger().Error("Unable to create a new Watcher: %s", err.Error())
		return
	}
	err = watcher.Watch(runBaseDir)
	if err != nil {
		logging.GetLogger().Error("Unable to Watch %s: %s", runBaseDir, err.Error())
		return
	}

	u.initialize()

	for {
		select {
		case ev := <-watcher.Event:
			if ev.Mask&inotify.IN_CREATE > 0 {
				u.onNetNsCreated(ev.Name)
			}
			if ev.Mask&inotify.IN_DELETE > 0 {
				u.onNetNsDeleted(ev.Name)
			}

		case err := <-watcher.Error:
			logging.GetLogger().Error("Error while watching network namespace: %s", err.Error())
		}
	}
}
開發者ID:razorinc,項目名稱:skydive,代碼行數:32,代碼來源:netns.go

示例11: FlowsFromSFlowSample

func FlowsFromSFlowSample(ft *Table, sample *layers.SFlowFlowSample, setter FlowProbePathSetter) []*Flow {
	flows := []*Flow{}

	for _, rec := range sample.Records {

		/* FIX(safchain): just keeping the raw packet for now */
		switch rec.(type) {
		case layers.SFlowRawPacketFlowRecord:
			/* We only support RawPacket from SFlow probe */
		case layers.SFlowExtendedSwitchFlowRecord:
			logging.GetLogger().Debug("1st layer is not SFlowRawPacketFlowRecord type")
			continue
		default:
			logging.GetLogger().Critical("1st layer is not a SFlow supported type")
			continue
		}

		record := rec.(layers.SFlowRawPacketFlowRecord)

		flow := FlowFromGoPacket(ft, &record.Header, setter)
		if flow != nil {
			flows = append(flows, flow)
		}
	}

	return flows
}
開發者ID:fdebonneval,項目名稱:skydive,代碼行數:27,代碼來源:flow.go

示例12: triggerResync

func (c *Forwarder) triggerResync() {
	logging.GetLogger().Infof("Start a resync of the graph")

	hostname, err := os.Hostname()
	if err != nil {
		logging.GetLogger().Errorf("Unable to retrieve the hostname: %s", err.Error())
		return
	}

	c.Graph.Lock()
	defer c.Graph.Unlock()

	// request for deletion of everythin belonging to host node
	root := c.Graph.GetNode(Identifier(hostname))
	if root == nil {
		return
	}
	c.Client.SendWSMessage(WSMessage{"SubGraphDeleted", root})

	// re-added all the nodes and edges
	nodes := c.Graph.GetNodes()
	for _, n := range nodes {
		c.Client.SendWSMessage(WSMessage{"NodeAdded", n})
	}

	edges := c.Graph.GetEdges()
	for _, e := range edges {
		c.Client.SendWSMessage(WSMessage{"EdgeAdded", e})
	}
}
開發者ID:lebauce,項目名稱:skydive,代碼行數:30,代碼來源:forwarder.go

示例13: Start

func (a *Agent) Start() {
	var err error

	go a.WSServer.ListenAndServe()

	addr, port, err := config.GetAnalyzerClientAddr()
	if err != nil {
		logging.GetLogger().Errorf("Unable to parse analyzer client %s", err.Error())
		os.Exit(1)
	}

	if addr != "" {
		authOptions := &shttp.AuthenticationOpts{
			Username: config.GetConfig().GetString("agent.analyzer_username"),
			Password: config.GetConfig().GetString("agent.analyzer_password"),
		}
		authClient := shttp.NewAuthenticationClient(addr, port, authOptions)
		a.WSClient, err = shttp.NewWSAsyncClient(addr, port, "/ws", authClient)
		if err != nil {
			logging.GetLogger().Errorf("Unable to instantiate analyzer client %s", err.Error())
			os.Exit(1)
		}

		graph.NewForwarder(a.WSClient, a.Graph)
		a.WSClient.Connect()

		// send a first reset event to the analyzers
		a.Graph.DelSubGraph(a.Root)
	}

	a.TopologyProbeBundle = tprobes.NewTopologyProbeBundleFromConfig(a.Graph, a.Root)
	a.TopologyProbeBundle.Start()

	a.FlowProbeBundle = fprobes.NewFlowProbeBundleFromConfig(a.TopologyProbeBundle, a.Graph)
	a.FlowProbeBundle.Start()

	if addr != "" {
		a.EtcdClient, err = etcd.NewEtcdClientFromConfig()
		if err != nil {
			logging.GetLogger().Errorf("Unable to start etcd client %s", err.Error())
			os.Exit(1)
		}

		captureHandler := &api.BasicApiHandler{
			ResourceHandler: &api.CaptureHandler{},
			EtcdKeyAPI:      a.EtcdClient.KeysApi,
		}

		l, err := fprobes.NewOnDemandProbeListener(a.FlowProbeBundle, a.Graph, captureHandler)
		if err != nil {
			logging.GetLogger().Errorf("Unable to start on-demand flow probe %s", err.Error())
			os.Exit(1)
		}
		a.OnDemandProbeListener = l
		a.OnDemandProbeListener.Start()
	}

	go a.HTTPServer.ListenAndServe()
}
開發者ID:fdebonneval,項目名稱:skydive,代碼行數:59,代碼來源:agent.go

示例14: NewFlowProbeBundleFromConfig

func NewFlowProbeBundleFromConfig(tb *probes.TopologyProbeBundle, g *graph.Graph) *FlowProbeBundle {
	list := config.GetConfig().GetStringSlice("agent.flow.probes")

	logging.GetLogger().Infof("Flow probes: %v", list)

	gfe := mappings.NewGraphFlowEnhancer(g)

	var aclient *analyzer.Client

	addr, port, err := config.GetAnalyzerClientAddr()
	if err != nil {
		logging.GetLogger().Errorf("Unable to parse analyzer client: %s", err.Error())
		return nil
	}

	if addr != "" {
		aclient, err = analyzer.NewClient(addr, port)
		if err != nil {
			logging.GetLogger().Errorf("Analyzer client error %s:%d : %s", addr, port, err.Error())
			return nil
		}
	}

	probes := make(map[string]probe.Probe)
	for _, t := range list {
		if _, ok := probes[t]; ok {
			continue
		}

		switch t {
		case "ovssflow":
			ofe := mappings.NewOvsFlowEnhancer(g)
			pipeline := mappings.NewFlowMappingPipeline(gfe, ofe)

			o := NewOvsSFlowProbesHandler(tb, g, pipeline, aclient)
			if o != nil {
				probes[t] = o
			}
		case "pcap":
			pipeline := mappings.NewFlowMappingPipeline(gfe)

			o := NewPcapProbesHandler(tb, g, pipeline, aclient)
			if o != nil {
				probes[t] = o
			}
		default:
			logging.GetLogger().Errorf("unknown probe type %s", t)
		}
	}

	p := probe.NewProbeBundle(probes)

	return &FlowProbeBundle{
		ProbeBundle: *p,
		Graph:       g,
	}
}
開發者ID:lebauce,項目名稱:skydive,代碼行數:57,代碼來源:probes.go

示例15: processGraphMessage

func (c *WSClient) processGraphMessage(m []byte) {
	c.server.Graph.Lock()
	defer c.server.Graph.Unlock()

	msg, err := UnmarshalWSMessage(m)
	if err != nil {
		logging.GetLogger().Errorf("Graph: Unable to parse the event %s: %s", msg, err.Error())
		return
	}
	g := c.server.Graph

	switch msg.Type {
	case "SyncRequest":
		reply := WSMessage{
			Type: "SyncReply",
			Obj:  c.server.Graph,
		}
		c.send <- []byte(reply.String())

	case "SubGraphDeleted":
		n := msg.Obj.(*Node)

		logging.GetLogger().Debugf("Got SubGraphDeleted event from the node %s", n.ID)

		node := g.GetNode(n.ID)
		if node != nil {
			g.DelSubGraph(node)
		}
	case "NodeUpdated":
		n := msg.Obj.(*Node)
		node := g.GetNode(n.ID)
		if node != nil {
			g.SetMetadata(node, n.metadata)
		}
	case "NodeDeleted":
		g.DelNode(msg.Obj.(*Node))
	case "NodeAdded":
		n := msg.Obj.(*Node)
		if g.GetNode(n.ID) == nil {
			g.AddNode(n)
		}
	case "EdgeUpdated":
		e := msg.Obj.(*Edge)
		edge := g.GetEdge(e.ID)
		if edge != nil {
			g.SetMetadata(edge, e.metadata)
		}
	case "EdgeDeleted":
		g.DelEdge(msg.Obj.(*Edge))
	case "EdgeAdded":
		e := msg.Obj.(*Edge)
		if g.GetEdge(e.ID) == nil {
			g.AddEdge(e)
		}
	}
}
開發者ID:lebauce,項目名稱:skydive,代碼行數:56,代碼來源:server.go


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