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


Golang logger.GetLogger函數代碼示例

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


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

示例1: PostConstruct

func (c *HomeCloud) PostConstruct() error {

	c.log = logger.GetLogger("HomeCloud")

	c.ExportRPCServices()
	c.ensureSiteExists()

	ledController := c.Conn.GetServiceClient("$home/led-controller")
	err := ledController.Call("enableControl", nil, nil, 0)
	if err != nil {
		c.log.Infof("Failed to enable control on LED controller: %s", err)
	}

	if syncEnabled {
		// We wait for at least one sync to happen, or fail
		<-c.StartSyncing(config.MustDuration("homecloud.sync.interval"))
	}

	// This is required to enable sphere-reset to clear out redis, then push this empty db to
	// cloud.
	if config.Bool(false, "clearcloud") {
		c.log.Infof("Just clearing cloud so exiting now!")
		os.Exit(0)
	}

	c.AutoStartModules()

	return nil
}
開發者ID:mash0304,項目名稱:sphere-go-homecloud,代碼行數:29,代碼來源:HomeCloud.go

示例2: NewStateManager

func NewStateManager() StateManager {

	return &NinjaStateManager{
		lastStates: make(map[string]*LastState),
		log:        logger.GetLogger("sphere-go-homecloud-state"),
	}
}
開發者ID:kpernyer,項目名稱:sphere-go-homecloud,代碼行數:7,代碼來源:StateManager.go

示例3: Connect

// Connect Builds a new ninja connection to the MQTT broker, using the given client ID
func Connect(clientID string) (*Connection, error) {

	log := logger.GetLogger(fmt.Sprintf("%s.connection", clientID))

	conn := Connection{
		log:      log,
		services: []model.ServiceAnnouncement{},
	}

	mqttURL := fmt.Sprintf("%s:%d", config.MustString("mqtt", "host"), config.MustInt("mqtt", "port"))

	log.Infof("Connecting to %s using cid:%s", mqttURL, clientID)

	conn.mqtt = bus.MustConnect(mqttURL, clientID)

	log.Infof("Connected")

	conn.rpc = rpc.NewClient(conn.mqtt, json2.NewClientCodec())
	conn.rpcServer = rpc.NewServer(conn.mqtt, json2.NewCodec())

	// Add service discovery service. Responds to queries about services exposed in this process.
	discoveryService := &discoverService{&conn}
	_, err := conn.exportService(discoveryService, "$discover", &simpleService{*discoveryService.GetServiceAnnouncement()})
	if err != nil {
		log.Fatalf("Could not expose discovery service: %s", err)
	}

	return &conn, nil
}
開發者ID:kpernyer,項目名稱:go-ninja,代碼行數:30,代碼來源:Connection.go

示例4: NewCertPane

func NewCertPane(conn bus.Bus) *CertPane {

	log := logger.GetLogger("CertPane")

	pane := &CertPane{
		log: log,
	}

	if !enableCertificationPane {
		return pane
	}

	_, err := conn.Subscribe("$location/waypoints", func(topic string, payload []byte) {
		var waypoints int
		err := json.Unmarshal(payload, &waypoints)
		if err != nil {
			log.Infof("Failed to parse incoming waypoints json %s, from %s", err, payload)
		} else {
			log.Infof("Number of waypoints: %d", waypoints)
		}
		pane.waypoints = waypoints
	})

	if err != nil {
		log.HandleError(err, "Could not start subscription to waypoint topic")
	}

	pane.StartRssi(conn)

	return pane
}
開發者ID:lindsaymarkward,項目名稱:sphere-go-led-controller,代碼行數:31,代碼來源:Certification.go

示例5: CreateLightDevice

func CreateLightDevice(driver ninja.Driver, info *model.Device, conn *ninja.Connection) (*LightDevice, error) {

	d := &LightDevice{
		baseDevice: baseDevice{
			conn:   conn,
			driver: driver,
			log:    logger.GetLogger("LightDevice - " + *info.Name),
			info:   info,
		},
	}

	err := conn.ExportDevice(d)
	if err != nil {
		d.log.Fatalf("Failed to export device %s: %s", *info.Name, err)
	}

	methods := []string{"setBatch"}
	events := []string{}

	err = conn.ExportChannelWithSupported(d, &LightBatchChannel{d}, "batch", &methods, &events)
	if err != nil {
		d.log.Fatalf("Failed to create batch channel: %s", err)
	}

	d.log.Infof("Created")

	return d, nil
}
開發者ID:kpernyer,項目名稱:go-ninja,代碼行數:28,代碼來源:light.go

示例6: main

func main() {

	/*
		go func() {
			log.Printf("Starting pprof server")
			log.Println(http.ListenAndServe(":6060", nil))
		}()
		//*/

	log := logger.GetLogger("LED-controller")

	conn, err := ninja.Connect(drivername)

	if err != nil {
		log.FatalErrorf(err, "Failed to connect to mqtt")
	}

	controller, err := NewLedController(conn)

	if err != nil {
		log.FatalErrorf(err, "Failed to create led controller")
	}

	enableControl := config.Bool(false, "enableControl")

	controller.start(enableControl)

	blah := make(chan os.Signal, 1)
	signal.Notify(blah, os.Interrupt, os.Kill)

	// Block until a signal is received.
	x := <-blah
	log.Infof("Got signal:", x)

}
開發者ID:lindsaymarkward,項目名稱:sphere-go-led-controller,代碼行數:35,代碼來源:main.go

示例7: NewPane

func NewPane(conn net.Conn) *Pane {

	pane := &Pane{
		conn:           conn,
		log:            logger.GetLogger("Pane"),
		Disconnected:   make(chan bool, 1),
		incoming:       gob.NewDecoder(conn),
		outgoing:       gob.NewEncoder(conn),
		enabled:        true,
		incomingFrames: make(chan *Incoming, 1),
	}

	// Ping the remote pane continuously so we can see if it's disappeared.
	// This is kinda dumb.
	go func() {
		for {
			if !pane.enabled {
				break
			}
			pane.out(Outgoing{})
			time.Sleep(time.Second)
		}
	}()

	go pane.listen()

	return pane
}
開發者ID:lindsaymarkward,項目名稱:sphere-go-led-controller,代碼行數:28,代碼來源:RemotePane.go

示例8: CreateSwitchDevice

func CreateSwitchDevice(driver ninja.Driver, info *model.Device, conn *ninja.Connection) (*SwitchDevice, error) {

	d := &SwitchDevice{
		baseDevice: baseDevice{
			conn:   conn,
			driver: driver,
			log:    logger.GetLogger("SwitchDevice - " + *info.Name),
			info:   info,
		},
	}

	err := conn.ExportDevice(d)
	if err != nil {
		d.log.Fatalf("Failed to export device %s: %s", *info.Name, err)
	}

	d.onOffChannel = channels.NewOnOffChannel(d)
	d.conn.ExportChannel(d, d.onOffChannel, "on-off")
	if err != nil {
		d.log.Fatalf("Failed to export on-off channel: %s", err)
	}

	d.log.Infof("Created")

	return d, nil
}
開發者ID:kpernyer,項目名稱:go-ninja,代碼行數:26,代碼來源:switch.go

示例9: safeLog

// this function will always return a logger that can be used even if the
// support object has not been initialized in the correct sequence or with
// the correct arguments.
func safeLog(m *ModuleSupport, info *model.Module) *logger.Logger {
	if m == nil || m.Log == nil {
		return logger.GetLogger(fmt.Sprintf("%s.module", safeID(info)))
	} else {
		return m.Log
	}
}
開發者ID:kpernyer,項目名稱:go-ninja,代碼行數:10,代碼來源:ModuleSupport.go

示例10: NewSystemPane

func NewSystemPane(conn *ninja.Connection) Pane {

	pane := &SystemPane{
		log:   logger.GetLogger("SystemPane"),
		code:  "0000",
		color: "green",
	}

	status := conn.GetServiceClient("$device/:deviceId/component/:componentId")
	status.OnEvent("status", func(statusEvent *StatusEvent, values map[string]string) bool {
		if deviceId, ok := values["deviceId"]; !ok {
			return true
		} else if deviceId != config.Serial() {
			return true
		} else {
			params, _ := json.Marshal(statusEvent)
			pane.log.Infof("$device/%s/component/%s - %s", deviceId, values["componentId"], params)
			pane.code = statusEvent.Code
			pane.color = statusEvent.Color
			if pane.color == "" {
				pane.color = "green"
			}
			return true
		}
	})

	return pane
}
開發者ID:ninjasphere,項目名稱:sphere-go-led-controller,代碼行數:28,代碼來源:SystemPane.go

示例11: NewLifxDriver

func NewLifxDriver() {
	d := &LifxDriver{
		log:     logger.GetLogger(info.Name),
		client:  lifx.NewClient(),
		devices: make(map[string]*lifxDevice),
	}

	conn, err := ninja.Connect(info.ID)
	if err != nil {
		d.log.Fatalf("Failed to connect to MQTT: %s", err)
	}

	err = conn.ExportDriver(d)

	if err != nil {
		d.log.Fatalf("Failed to export driver: %s", err)
	}

	go func() {

		sub := d.client.Subscribe()

		for {

			event := <-sub.Events

			switch evnt := event.(type) {
			case *lifx.Bulb:
				if isUnique(evnt) {
					d.log.Infof("creating new light")
					_, err := d.newLight(evnt)
					if err != nil {
						d.log.HandleErrorf(err, "Error creating light instance")
					}
					seenlights = append(seenlights, evnt) //TODO remove bulbs that haven't been seen in a while?
					err = d.client.GetBulbState(evnt)

					if err != nil {
						d.log.Warningf("unable to intiate bulb state request %s", err)
					}
				}
			case *lifx.LightSensorState:
				// handle these vents for each bulb
				if d.devices[evnt.GetLifxAddress()] != nil {
					d.devices[evnt.GetLifxAddress()].illuminance.SendState(float64(evnt.Lux))
				}

			default:
				d.log.Infof("Event %v", event)
			}

		}

	}()

	go d.publishSensorData()

	d.conn = conn
}
開發者ID:ninjasphere,項目名稱:driver-go-lifx,代碼行數:59,代碼來源:driver.go

示例12: main

func main() {

	client.Start()

	s := make(chan os.Signal, 1)
	signal.Notify(s, os.Interrupt, os.Kill)
	logger.GetLogger("Client").Infof("Got signal: %v", <-s)
}
開發者ID:kpernyer,項目名稱:sphere-client,代碼行數:8,代碼來源:main.go

示例13: PostConstruct

func (m *DeviceManager) PostConstruct() error {
	m.log = logger.GetLogger("DeviceManager")
	err := m.Start()
	if err != nil {
		return err
	}
	return nil
}
開發者ID:kpernyer,項目名稱:sphere-go-homecloud,代碼行數:8,代碼來源:DeviceManager.go

示例14: StartSonosDriver

func StartSonosDriver() {
	d := &sonosDriver{
		log:     logger.GetLogger(info.Name),
		players: make(map[string]*sonosZonePlayer),
	}

	conn, err := ninja.Connect(info.ID)
	if err != nil {
		d.log.Fatalf("Failed to connect to MQTT: %s", err)
	}

	err = conn.ExportDriver(d)

	if err != nil {
		d.log.Fatalf("Failed to export driver: %s", err)
	}

	if nil != err {
		nlog.HandleError(err, "Could not locate interface to bind to")
	}

	d.reactor = sonos.MakeReactor(EventingPort)

	go func() {
		events := d.reactor.Channel()

		d.log.Infof("waiting for events.")

		for {
			event := <-events

			switch v := event.(type) {
			case upnp.MusicServicesEvent: // this cuts down the events by a factor of 4
				d.log.Infof("processing event %T", v)

				// because event is a big ball of string it is easier to just iterate over all players
				// and update them all when an event occurs
				for id, player := range d.players {
					d.log.Infof("Updating state for %s", id)
					player.updateState()
				}

			}

			// switch v := event.(type) {
			// case upnp.RenderingControlEvent:
			// 	d.log.Infof(spew.Sprintf("Volume %v", v.LastChange.InstanceID.Volume))
			// case upnp.AVTransportEvent:
			// 	d.log.Infof(spew.Sprintf("TransportState %v", v.LastChange.InstanceID.TransportState))
			// }

			//spew.Dump(event)

		}
	}()

	d.conn = conn
}
開發者ID:ninjasphere,項目名稱:driver-go-sonos,代碼行數:58,代碼來源:driver.go

示例15: NewMatrix

func NewMatrix(pane pane) *Matrix {

	matrix := &Matrix{
		log:          logger.GetLogger("Matrix"),
		Disconnected: make(chan bool, 1),
		pane:         pane,
	}

	return matrix
}
開發者ID:lindsaymarkward,項目名稱:sphere-go-led-controller,代碼行數:10,代碼來源:RemoteMatrix.go


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