Use golang log
This commit is contained in:
parent
bdd9b88327
commit
7da1b802c5
|
@ -1,7 +1,7 @@
|
|||
package gobot
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
)
|
||||
|
||||
type connection struct {
|
||||
|
@ -34,22 +34,22 @@ func NewConnection(adaptor AdaptorInterface, r *Robot) *connection {
|
|||
}
|
||||
|
||||
func (c *connection) Connect() bool {
|
||||
fmt.Println("Connecting to " + c.Name + " on port " + c.Port + "...")
|
||||
log.Println("Connecting to " + c.Name + " on port " + c.Port + "...")
|
||||
return c.Adaptor.Connect()
|
||||
}
|
||||
|
||||
func (c *connection) Disconnect() bool {
|
||||
fmt.Println("Disconnecting " + c.Name + "...")
|
||||
log.Println("Disconnecting " + c.Name + "...")
|
||||
return c.Adaptor.Disconnect()
|
||||
}
|
||||
|
||||
func (c *connection) Finalize() bool {
|
||||
fmt.Println("Finalizing " + c.Name + "...")
|
||||
log.Println("Finalizing " + c.Name + "...")
|
||||
return c.Adaptor.Finalize()
|
||||
}
|
||||
|
||||
func (c *connection) Reconnect() bool {
|
||||
fmt.Println("Reconnecting to " + c.Name + " on port " + c.Port + "...")
|
||||
log.Println("Reconnecting to " + c.Name + " on port " + c.Port + "...")
|
||||
return c.Adaptor.Reconnect()
|
||||
}
|
||||
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
package gobot
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
)
|
||||
|
||||
type device struct {
|
||||
|
@ -27,7 +27,7 @@ func NewDevice(driver DriverInterface, r *Robot) *device {
|
|||
}
|
||||
|
||||
func (d *device) Start() bool {
|
||||
fmt.Println("Device " + d.Name + " started")
|
||||
log.Println("Device " + d.Name + " started")
|
||||
return d.Driver.Start()
|
||||
}
|
||||
|
||||
|
|
|
@ -3,11 +3,18 @@ package gobot
|
|||
import (
|
||||
. "github.com/onsi/ginkgo"
|
||||
. "github.com/onsi/gomega"
|
||||
|
||||
"log"
|
||||
"testing"
|
||||
)
|
||||
|
||||
type null struct{}
|
||||
|
||||
func (null) Write(p []byte) (int, error) {
|
||||
return len(p), nil
|
||||
}
|
||||
|
||||
func TestGobot(t *testing.T) {
|
||||
log.SetOutput(new(null))
|
||||
RegisterFailHandler(Fail)
|
||||
RunSpecs(t, "Gobot Suite")
|
||||
}
|
||||
|
|
17
robot.go
17
robot.go
|
@ -2,6 +2,7 @@ package gobot
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
"math/rand"
|
||||
"time"
|
||||
)
|
||||
|
@ -55,27 +56,27 @@ func (r *Robot) initCommands() {
|
|||
|
||||
func (r *Robot) initConnections() {
|
||||
r.connections = make([]*connection, len(r.Connections))
|
||||
fmt.Println("Initializing connections...")
|
||||
log.Println("Initializing connections...")
|
||||
for i := range r.Connections {
|
||||
fmt.Sprintln("Initializing connection %v...", FieldByNamePtr(r.Connections[i], "Name"))
|
||||
log.Println("Initializing connection ", FieldByNamePtr(r.Connections[i], "Name"), "...")
|
||||
r.connections[i] = NewConnection(r.Connections[i], r)
|
||||
}
|
||||
}
|
||||
|
||||
func (r *Robot) initDevices() {
|
||||
r.devices = make([]*device, len(r.Devices))
|
||||
fmt.Println("Initializing devices...")
|
||||
log.Println("Initializing devices...")
|
||||
for i := range r.Devices {
|
||||
fmt.Sprintln("Initializing device %v...", FieldByNamePtr(r.Devices[i], "Name"))
|
||||
log.Println("Initializing device ", FieldByNamePtr(r.Devices[i], "Name"), "...")
|
||||
r.devices[i] = NewDevice(r.Devices[i], r)
|
||||
}
|
||||
}
|
||||
|
||||
func (r *Robot) startConnections() bool {
|
||||
fmt.Println("Starting connections...")
|
||||
log.Println("Starting connections...")
|
||||
success := true
|
||||
for i := range r.connections {
|
||||
fmt.Println("Starting connection " + r.connections[i].Name + "...")
|
||||
log.Println("Starting connection " + r.connections[i].Name + "...")
|
||||
if r.connections[i].Connect() == false {
|
||||
success = false
|
||||
break
|
||||
|
@ -85,10 +86,10 @@ func (r *Robot) startConnections() bool {
|
|||
}
|
||||
|
||||
func (r *Robot) startDevices() bool {
|
||||
fmt.Println("Starting devices...")
|
||||
log.Println("Starting devices...")
|
||||
success := true
|
||||
for i := range r.devices {
|
||||
fmt.Println("Starting device " + r.devices[i].Name + "...")
|
||||
log.Println("Starting device " + r.devices[i].Name + "...")
|
||||
if r.devices[i].Start() == false {
|
||||
success = false
|
||||
break
|
||||
|
|
Loading…
Reference in New Issue